| 1 |
// signal.ck : signaling events |
| 2 |
|
| 3 |
// declare an event |
| 4 |
Event e; |
| 5 |
|
| 6 |
// declare function |
| 7 |
fun void hi( Event e ) |
| 8 |
{ |
| 9 |
// wait on event e |
| 10 |
e => now; |
| 11 |
|
| 12 |
// this only happens AFTER e is signaled |
| 13 |
<<<"success">>>; |
| 14 |
} |
| 15 |
|
| 16 |
// spork shred with e |
| 17 |
spork ~ hi( e ); |
| 18 |
|
| 19 |
// yield to give the shred a chance to run (alternative: advance time) |
| 20 |
me.yield(); |
| 21 |
|
| 22 |
// signal e |
| 23 |
e.signal(); |
| 24 |
|
| 25 |
// advance time to let the other shred run |
| 26 |
// (the parent shred will free the child shred) |
| 27 |
// (alternative: me.yield()) |
| 28 |
1::samp => now; |