source: tests/exceptions/cancel/thread.cfa @ 2cf3b87

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since 2cf3b87 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
RevLine 
[ab8c6a6]1// Try cancelling a thread.
2
3#include <thread.hfa>
4
[d00d581]5exception internal_error {};
6vtable(internal_error) internal_vt;
[ab8c6a6]7
8thread WillCancel {};
9
10const char * msg(ThreadCancelled(WillCancel) * this) {
11        return "ThreadCancelled(WillCancel)";
12}
13
14void main(WillCancel &) {
15        printf("1");
[ecfd758]16        cancel_stack((internal_error){&internal_vt});
[ab8c6a6]17        printf("!");
18}
19
20void explicit() {
21        try {
22                printf("0");
23                WillCancel cancel;
24                printf("1");
25                join(cancel);
26                printf("4");
[8edbe40]27        } catchResume (ThreadCancelled(WillCancel) * error) {
[ab8c6a6]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");
[8edbe40]44        } catchResume (ThreadCancelled(WillCancel) * error) {
[ab8c6a6]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.