summaryrefslogtreecommitdiff
path: root/docs/examples/pilib/scheduler.scala
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/pilib/scheduler.scala')
-rw-r--r--docs/examples/pilib/scheduler.scala42
1 files changed, 21 insertions, 21 deletions
diff --git a/docs/examples/pilib/scheduler.scala b/docs/examples/pilib/scheduler.scala
index 8946a5a0b2..9205ae3f0c 100644
--- a/docs/examples/pilib/scheduler.scala
+++ b/docs/examples/pilib/scheduler.scala
@@ -7,14 +7,14 @@ object scheduler {
/**
* Random number generator.
*/
- val random = new java.util.Random()
+ val random = new util.Random()
//***************** Scheduler ******************//
/**
* A cell of the scheduler whose attached agent is allowed to start.
*/
- def A(a: Chan[unit], b: Chan[unit])(d: Chan[unit], c: Chan[unit]): unit = {
+ def A(a: Chan[Unit], b: Chan[Unit])(d: Chan[Unit], c: Chan[Unit]) {
///- ... complete here ...
choice ( a * { x => C(a, b)(d, c) })
///+
@@ -23,7 +23,7 @@ object scheduler {
/**
* A cell of the scheduler in another intermediate state.
*/
- def C(a: Chan[unit], b: Chan[unit])(d: Chan[unit], c: Chan[unit]): unit = {
+ def C(a: Chan[Unit], b: Chan[Unit])(d: Chan[Unit], c: Chan[Unit]) {
///- ... complete here ...
choice (c * { x => B(a, b)(d, c) })
///+
@@ -32,7 +32,7 @@ object scheduler {
/**
* A cell of the scheduler whose attached agent is allowed to finish.
*/
- def B(a: Chan[unit], b: Chan[unit])(d: Chan[unit], c: Chan[unit]): unit = {
+ def B(a: Chan[Unit], b: Chan[Unit])(d: Chan[Unit], c: Chan[Unit]) {
///- ... complete here ...
// choice (b * { x => D(a, b)(d, c) }) // incorrect naive solution
choice (
@@ -45,7 +45,7 @@ object scheduler {
/**
* A cell of the scheduler whose attached agent is not yet allowed to start.
*/
- def D(a: Chan[unit], b: Chan[unit])(d: Chan[unit], c: Chan[unit]): unit = {
+ def D(a: Chan[Unit], b: Chan[Unit])(d: Chan[Unit], c: Chan[Unit]) {
///- ... complete here ...
choice (d(()) * A(a, b)(d, c))
///+
@@ -53,16 +53,16 @@ object scheduler {
//***************** Agents ******************//
- def agent(i: Int)(a: Chan[unit], b: Chan[unit]): unit = {
+ def agent(i: Int)(a: Chan[Unit], b: Chan[Unit]) {
// 50% chance that we sleep forever
if (i == 0 && random.nextInt(10) < 5) {
- a.attach(x => System.out.println("Start and sleeps ----> " + i))
+ a.attach(x => println("Start and sleeps ----> " + i))
Thread.sleep(random.nextInt(1000))
a.write(())
}
else {
- a.attach(x => System.out.println("Start ----> " + i))
- b.attach(x => System.out.println("Stop -> " + i))
+ a.attach(x => println("Start ----> " + i))
+ b.attach(x => println("Stop -> " + i))
Thread.sleep(random.nextInt(1000))
a.write(())
Thread.sleep(random.nextInt(1000))
@@ -77,7 +77,7 @@ object scheduler {
* Creates a scheduler for five agents (programs).
*/
- def main(args: Array[String]): unit = {
+ def main(args: Array[String]) {
val agentNb = 5
val agents = List.range(0, agentNb) map agent
scheduleAgents(agents)
@@ -89,22 +89,22 @@ object scheduler {
* A cell is modelled as a function that takes as parameters
* input and output channels and which returns nothing.
*/
- type Cell = (Chan[unit], Chan[unit]) => unit
+ type Cell = (Chan[Unit], Chan[Unit]) => Unit
/**
* Creates a cell composed of two cells linked together.
*/
def join(cell1: Cell, cell2: Cell): Cell =
- (l: Chan[unit], r: Chan[unit]) => {
- val link = new Chan[unit];
+ (l: Chan[Unit], r: Chan[Unit]) => {
+ val link = new Chan[Unit];
spawn < cell1(l, link) | cell2(link, r) >
};
/**
* Links the output of a cell to its input.
*/
- def close(cell: Cell): unit = {
- val a = new Chan[unit]
+ def close(cell: Cell) {
+ val a = new Chan[Unit]
cell(a, a)
}
@@ -117,25 +117,25 @@ object scheduler {
/**
* Creates a cell consisting of a chain of cells.
*/
- def makeRing(cells: List[Cell]): unit =
+ def makeRing(cells: List[Cell]): Unit =
close(chain(cells))
/**
* An agent is modelled as a function that takes as parameters channels to
* signal that it has started or finished.
*/
- type Agent = (Chan[unit], Chan[unit]) => unit
+ type Agent = (Chan[Unit], Chan[Unit]) => Unit
/**
* Takes a list of agents and schedules them.
*/
- def scheduleAgents(agents: List[Agent]): unit = {
+ def scheduleAgents(agents: List[Agent]) {
var firstAgent = true;
val cells = agents map (ag => {
- val a = new Chan[unit];
- val b = new Chan[unit];
+ val a = new Chan[Unit];
+ val b = new Chan[Unit];
spawn < ag(a, b) >;
- (d: Chan[unit], c: Chan[unit]) => if (firstAgent) {
+ (d: Chan[Unit], c: Chan[Unit]) => if (firstAgent) {
firstAgent = false;
A(a, b)(d, c)
}