Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | #include <cc++/thread.h> |
| 2 | #include <cstdio> |
| 3 | #include <cstring> |
| 4 | #include <iostream> |
| 5 | |
| 6 | #ifdef CCXX_NAMESPACES |
| 7 | using namespace std; |
| 8 | using namespace ost; |
| 9 | #endif |
| 10 | |
| 11 | // Test if cancellation unwinds stack frame |
| 12 | // |
| 13 | |
| 14 | class myObject |
| 15 | { |
| 16 | public: |
| 17 | myObject() |
| 18 | {cout << "created auto object on stack" << endl;}; |
| 19 | |
| 20 | ~myObject() |
| 21 | {cout << "destroyed auto object on cancel" << endl;}; |
| 22 | }; |
| 23 | |
| 24 | class myThread: public Thread |
| 25 | { |
| 26 | public: |
| 27 | myThread() : Thread() {}; |
| 28 | |
| 29 | void run(void) { |
| 30 | myObject obj; |
| 31 | setCancel(cancelImmediate); |
| 32 | Thread::sleep(TIMEOUT_INF); |
| 33 | } |
| 34 | |
| 35 | ~myThread() |
| 36 | {cout << "ending thread" << endl;}; |
| 37 | }; |
| 38 | |
| 39 | int main(int argc, char* argv[]) |
| 40 | { |
| 41 | cout << "starting thread" << endl; |
| 42 | myThread *th = new myThread(); |
| 43 | th->start(); |
| 44 | Thread::sleep(1000); // 1 second |
| 45 | delete th; // delete to join |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |