thread2.cpp

00001 #include <cc++/thread.h>
00002 #include <cstdio>
00003 #include <cstring>
00004 #include <iostream>
00005 
00006 #ifdef  CCXX_NAMESPACES
00007 using namespace std;
00008 using namespace ost;
00009 #endif
00010 
00011 // Test child thread destroying before father
00012 //
00013 class Child: public Thread
00014 {
00015 public:
00016         Child()
00017         { }
00018         void run() {
00019                 cout << "child start" << endl;
00020                 Thread::sleep(3000);
00021                 cout << "child end" << endl;
00022         }
00023         void final() {
00024 //              delete this;
00025         }
00026 };
00027 
00028 class Father: public Thread
00029 {
00030 public:
00031         Father()
00032         { }
00033         void run() {
00034                 cout << "starting child thread" << endl;
00035                 Thread *th = new Child();
00036                 th->detach();
00037                 Thread::sleep(1000);
00038                 cout << "father end" << endl;
00039         }
00040         void final() {
00041                 // delete this; - not used since detached threads self delete
00042                 // reset memory to test access violation
00043                 memset(this,0,sizeof(*this));
00044         }
00045 };
00046 
00047 int main(int argc, char* argv[])
00048 {
00049         cout << "starting father thread" << endl;
00050         Father *th = new Father();
00051         th->start();
00052         Thread::sleep(10000);
00053 
00054         return 0;
00055 }
00056 

Generated on Fri Feb 23 09:55:13 2007 for GNU CommonC++ by  doxygen 1.5.1