| 1 |
// name: spork3-exit.ck |
| 2 |
// desc: how to spork and terminate specific child shreds |
| 3 |
|
| 4 |
// a function to spork |
| 5 |
fun void go( int n ) |
| 6 |
{ |
| 7 |
while( true ) |
| 8 |
{ |
| 9 |
<<< "go", n >>>; |
| 10 |
250::ms => now; |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
// spork three shreds, save the resulting shred reference |
| 15 |
spork ~ go(1) @=> Shred s1; |
| 16 |
spork ~ go(2) @=> Shred s2; |
| 17 |
spork ~ go(3) @=> Shred s3; |
| 18 |
|
| 19 |
// exit the shreds |
| 20 |
1::second => now; |
| 21 |
s1.exit(); |
| 22 |
1::second => now; |
| 23 |
s2.exit(); |
| 24 |
1::second => now; |
| 25 |
s3.exit(); |
| 26 |
|
| 27 |
// yield this shred, give chance for s3 to run at current time |
| 28 |
me.yield(); |
| 29 |
// print done |
| 30 |
<<< "done...", "" >>>; |
| 31 |
|
| 32 |
// wait a bit more to see nothing is printed from child shreds |
| 33 |
1::second => now; |
| 34 |
|
| 35 |
// print out Shred functionality, if you are curious |
| 36 |
// Shred.help(); |
| 37 |
|
| 38 |
// print done |
| 39 |
<<< "exiting parent shred...", "" >>>; |