Check example code in.
[IRC.git] / Robust / src / Tests / TaskExample.java
1 class Example {
2     flag needoperation;
3     flag needprinting;
4     
5     int operation;
6     int x;
7     int y;
8     int z;
9 }
10
11 /* Startup object is generated with the initialstate flag set by the
12  *  system to start the computation up */
13
14 task Startup(StartupObject s {initialstate}) {
15     for(int i=0;i<10;i++) {
16         Example e=new Example() {needoperation};
17         e.x=i;
18         e.y=2;
19         e.operation=i%2;
20     }
21     
22     taskexit(s {!initialstate}); /* Turns initial state flag off, so this task won't refire */
23 }
24
25 /* Fails for x=1 */
26
27 task DoOperation(Example e{needoperation}) {
28     e.z=10*e.y/(e.x-1);
29
30     if (e.operation==0)
31         /* Print the result */
32         taskexit(e {!needoperation, needprinting});
33     else
34         /* Don't print the result */
35         taskexit(e {!needoperation});
36 }
37
38 /* Note that we can write arbitrary boolean expressions for flag
39  * expressions.  For example, needprinting && ! needoperation would
40  * also be a legal flag expression */
41
42 task DoPrint(Example e{needprinting}) {
43     System.printInt(e.z);
44     taskexit(e {!needprinting};
45 }