| 1 |
// 41.ck : event |
| 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 let the sporked shreds run and wait on event |
| 20 |
me.yield(); |
| 21 |
|
| 22 |
// signal e |
| 23 |
e.signal(); |
| 24 |
|
| 25 |
// yield again to let the other shred run (and print success) |
| 26 |
me.yield(); |
| 27 |
|
| 28 |
// FYI from here freeing the parent shred will free the child shred |