source: tests/exceptions/cancel/thread.cfa@ 550afde2

Last change on this file since 550afde2 was 3bf9d10, checked in by Peter A. Buhr <pabuhr@…>, 2 years ago

change printf to sout

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