Last change
on this file since c34bb1f was
27f2bef,
checked in by caparsons <caparson@…>, 15 months ago
|
added comment explaining test
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | #include <fstream.hfa> |
---|
2 | #include <thread.hfa> |
---|
3 | |
---|
4 | int num_links = 10; |
---|
5 | |
---|
6 | exception unwind { int num; }; |
---|
7 | vtable(unwind) unwind_vt; |
---|
8 | |
---|
9 | |
---|
10 | coroutine Node { int cnt; unwind except; }; |
---|
11 | void ?{}( Node & this, int cnt ) { this.cnt = cnt; } |
---|
12 | |
---|
13 | // builds a list of Node coroutines linked by their last resumer field |
---|
14 | // the (num_links + 1)th node then triggers unwinding of the list by throwing resumtions at the last resumer |
---|
15 | void main( Node & this ) with( this ) { |
---|
16 | sout | cnt; |
---|
17 | if ( cnt == 0 ) { |
---|
18 | except{ &unwind_vt, cnt }; |
---|
19 | resumeAt( resumer( this ), except ); |
---|
20 | return; |
---|
21 | } |
---|
22 | Node next{ cnt - 1 }; |
---|
23 | resume( next ); |
---|
24 | try { |
---|
25 | while( ! poll( this ) ) { yield(); } |
---|
26 | } catch( unwind * e ) { |
---|
27 | e->num++; |
---|
28 | if ( e->num != cnt ) { |
---|
29 | sout | "exception count and thread count should be consistent!"; |
---|
30 | abort(); |
---|
31 | } |
---|
32 | sout | e->num; |
---|
33 | if ( cnt == num_links ) return; |
---|
34 | except{ &unwind_vt, e->num }; |
---|
35 | resumeAt( resumer( this ), except ); |
---|
36 | } |
---|
37 | |
---|
38 | } |
---|
39 | |
---|
40 | int main() { |
---|
41 | sout | "main start"; |
---|
42 | Node n{ num_links }; |
---|
43 | resume( n ); |
---|
44 | sout | "main end"; |
---|
45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.