source: tests/exceptions/cancel/thread.cfa @ 26ca815

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 26ca815 was ab8c6a6, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Thread Cancellation, a test for it and a required fix to Specialization.

  • Property mode set to 100644
File size: 934 bytes
RevLine 
[ab8c6a6]1// Try cancelling a thread.
2
3#include <thread.hfa>
4#include <exception.hfa>
5
6TRIVIAL_EXCEPTION(internal_error);
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){});
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.