blob: 9894420e6fca7f4a8b12580e0852c63faee735f3 [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 child thread destroying before father
12//
13class Child: public Thread
14{
15public:
16 Child()
17 { }
18 void run() {
19 cout << "child start" << endl;
20 Thread::sleep(3000);
21 cout << "child end" << endl;
22 }
23 void final() {
24// delete this;
25 }
26};
27
28class Father: public Thread
29{
30public:
31 Father()
32 { }
33 void run() {
34 cout << "starting child thread" << endl;
35 Thread *th = new Child();
36 th->detach();
37 Thread::sleep(1000);
38 cout << "father end" << endl;
39 }
40 void final() {
41 // delete this; - not used since detached threads self delete
42 // reset memory to test access violation
43 memset(this,0,sizeof(*this));
44 }
45};
46
47int main(int argc, char* argv[])
48{
49 cout << "starting father thread" << endl;
50 Father *th = new Father();
51 th->start();
52 Thread::sleep(10000);
53
54 return 0;
55}
56