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