source: tests/exceptions/cancel/thread.cfa @ 0e34a14

ADTast-experimentalpthread-emulation
Last change on this file since 0e34a14 was d00d581, checked in by Henry Xue <y58xue@…>, 3 years ago

Update exception tests to use new syntax

  • Property mode set to 100644
File size: 951 bytes
Line 
1// Try cancelling a thread.
2
3#include <thread.hfa>
4
5exception internal_error {};
6vtable(internal_error) internal_vt;
7
8thread WillCancel {};
9
10const char * msg(ThreadCancelled(WillCancel) * this) {
11        return "ThreadCancelled(WillCancel)";
12}
13
14void main(WillCancel &) {
15        printf("1");
16        cancel_stack((internal_error){&internal_vt});
17        printf("!");
18}
19
20void explicit() {
21        try {
22                printf("0");
23                WillCancel cancel;
24                printf("1");
25                join(cancel);
26                printf("4");
27        } catchResume (ThreadCancelled(WillCancel) * error) {
28                printf("2");
29                if ((virtual internal_error *)error->the_exception) {
30                        printf("3");
31                }
32        }
33        printf("5\n");
34}
35
36void implicit() {
37        try {
38                {
39                        printf("0");
40                        WillCancel cancel;
41                        printf("1");
42                }
43                printf("4");
44        } catchResume (ThreadCancelled(WillCancel) * error) {
45                printf("2");
46                if ((virtual internal_error *)error->the_exception) {
47                        printf("3");
48                }
49        }
50        printf("5\n");
51}
52
53int main(int argc, char * argv[]) {
54        explicit();
55        implicit();
56}
Note: See TracBrowser for help on using the repository browser.