source: tests/exceptions/cor_resumer.cfa @ 9a01745

Last change on this file since 9a01745 was 7c2820e, checked in by caparsons <caparson@…>, 17 months ago

added exception thrown at main to the cor_resumer test

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include <fstream.hfa>
2#include <thread.hfa>
3
4int num_links = 10;
5
6exception unwind { int num; };
7vtable(unwind) unwind_vt;
8
9
10coroutine Node { int cnt;  unwind except; };
11void ?{}( 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
15void 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        poll();
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        except{ &unwind_vt, e->num };
34        resumeAt( resumer( this ), except );
35    }
36
37}
38
39int main() {
40        sout | "main start";
41    Node n{ num_links };
42    try {
43        resume( n );
44        poll();
45    } catch( unwind * e ) {}
46   
47        sout | "main end";
48}
Note: See TracBrowser for help on using the repository browser.