Debian Codegraph @

examples/event/broadcast.ck

raw
1 // broadcast.ck : event broadcast
2
3 // delcare event e
4 Event e;
5
6 // base function for shred
7 fun void hi( Event e )
8 {
9 // wait on event
10 e => now;
11
12 // print stuff out
13 <<<"success">>>;
14 }
15
16 // spork 4 shreds
17 spork ~ hi( e );
18 spork ~ hi( e );
19 spork ~ hi( e );
20 spork ~ hi( e );
21
22 // yield current shred (without advancing time)
23 // ... allow other shreds to start running ...
24 // (alternative: advance time to allow all shreds to start running)
25 me.yield();
26
27 // signal all shreds waiting on event e
28 e.broadcast();
29
30 // advance time since this parent shred will free all child shreds on exit
31 // (alternative: me.yield())
32 1::ms => now;