Debian Codegraph @

examples/event/signal4.ck

raw
1 // signal-4.ck : one event signals 4 shreds
2
3 // our event
4 Event e;
5
6 // the base function of our shreds
7 fun void hi( Event e, string id )
8 {
9 // time/event loop
10 while( true )
11 {
12 // wait on event
13 e => now;
14 <<<id>>>;
15 }
16 }
17
18 // spork our shreds with different strings
19 spork ~ hi( e, "yo" );
20 spork ~ hi( e, "hi" );
21 spork ~ hi( e, "hello" );
22 spork ~ hi( e, "hey come back here!" );
23
24 // may want to yield to give shreds chance to start
25 me.yield();
26
27 // time loop
28 while( true )
29 {
30 // signal one shred
31 e.signal();
32 // advance time by 1 second (alternative: me.yield())
33 1::second => now;
34 }