| 1 |
// test nested sporking, and accessing file-scope vars from |
| 2 |
// nested sporked member function |
| 3 |
|
| 4 |
// accessing this var |
| 5 |
5 => int a; |
| 6 |
|
| 7 |
// a (non-public) class |
| 8 |
// (public classes wouldn't be able to access file-scope vars) |
| 9 |
class Foo |
| 10 |
{ |
| 11 |
// a member function |
| 12 |
fun void update( float dt ) |
| 13 |
{ |
| 14 |
while( true ) |
| 15 |
{ |
| 16 |
// access global-scope var a |
| 17 |
a++; |
| 18 |
// print |
| 19 |
<<< a, dt >>>; |
| 20 |
// advance time |
| 21 |
200::ms => now; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
fun void go() |
| 26 |
{ |
| 27 |
// spork |
| 28 |
spork ~ this.update(2); |
| 29 |
// wait a long time (until the parent shred is done) |
| 30 |
eon => now; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
// instantiate a Foo |
| 35 |
Foo foo; |
| 36 |
// call go |
| 37 |
spork ~ foo.go(); |
| 38 |
// let time pass |
| 39 |
2.1::second => now; |
| 40 |
// (should remove child and grandchild shreds as this shred exits) |