blob: 3074088874c9083ca02f990612bb373da243c5a3 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001#include <cc++/thread.h>
2#include <cstdio>
3#include <cstring>
4#include <iostream>
5
6#ifdef CCXX_NAMESPACES
7using namespace std;
8using namespace ost;
9#endif
10
11// Test if cancellation unwinds stack frame
12//
13
14class myObject
15{
16public:
17 myObject()
18 {cout << "created auto object on stack" << endl;};
19
20 ~myObject()
21 {cout << "destroyed auto object on cancel" << endl;};
22};
23
24class myThread: public Thread
25{
26public:
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
39int 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