Last change
on this file since c3e510b was
c3e510b,
checked in by caparsons <caparson@…>, 15 months ago
|
added support for resuming at resumer, added test for support and cleaned up uneeded include in pingpong exception test
|
-
Property mode set to
100644
|
File size:
945 bytes
|
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 | coroutine Node { int cnt; unwind except; }; |
---|
10 | void ?{}( Node & this, int cnt ) { this.cnt = cnt; } |
---|
11 | |
---|
12 | void main( Node & this ) with( this ) { |
---|
13 | sout | cnt; |
---|
14 | if ( cnt == 0 ) { |
---|
15 | except{ &unwind_vt, cnt }; |
---|
16 | resumeAt( resumer( this ), except ); |
---|
17 | return; |
---|
18 | } |
---|
19 | Node next{ cnt - 1 }; |
---|
20 | resume( next ); |
---|
21 | try { |
---|
22 | while( ! poll( this ) ) { yield(); } |
---|
23 | } catch( unwind * e ) { |
---|
24 | e->num++; |
---|
25 | if ( e->num != cnt ) { |
---|
26 | sout | "exception count and thread count should be consistent!"; |
---|
27 | abort(); |
---|
28 | } |
---|
29 | sout | e->num; |
---|
30 | if ( cnt == num_links ) return; |
---|
31 | except{ &unwind_vt, e->num }; |
---|
32 | resumeAt( resumer( this ), except ); |
---|
33 | } |
---|
34 | |
---|
35 | } |
---|
36 | |
---|
37 | int main() { |
---|
38 | sout | "main start"; |
---|
39 | Node n{ num_links }; |
---|
40 | resume( n ); |
---|
41 | sout | "main end"; |
---|
42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.