source: tests/exceptions/cor_resumer.cfa @ 416b443

Last change on this file since 416b443 was 7c2820e, checked in by caparsons <caparson@…>, 11 months ago

added exception thrown at main to the cor_resumer test

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[c3e510b]1#include <fstream.hfa>
2#include <thread.hfa>
3
4int num_links = 10;
5
6exception unwind { int num; };
7vtable(unwind) unwind_vt;
8
[27f2bef]9
[c3e510b]10coroutine Node { int cnt;  unwind except; };
11void ?{}( Node & this, int cnt ) { this.cnt = cnt; }
12
[27f2bef]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
[c3e510b]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 {
[7c2820e]25        poll();
[c3e510b]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 };
[7c2820e]42    try {
43        resume( n );
44        poll();
45    } catch( unwind * e ) {}
46   
[c3e510b]47        sout | "main end";
48}
Note: See TracBrowser for help on using the repository browser.