00001 #include "nixsys.h"
00002 #include "thread.h"
00003 #include "semaphore.h"
00004
00005 using namespace std ;
00006 using namespace n2nc ;
00007
00008 n2nc::sync::Semaphore g_sem(0);
00009
00010 void* fun1(void *arg1){
00011 cerr << "fun1 callled with args: " << (char*)arg1 ;
00012 cerr << " Thread name: " << n2nc::sync::Thread::getCurrent().toString() << endl ;
00013 sleep(3);
00014
00015 g_sem.post();
00016
00017 return (void*)"fun1" ;
00018 }
00019
00020 int fun1_exit(void* arg1){
00021 cerr << "fun1 exited with args: " << (char*)arg1 ;
00022 cerr << " Thread name: " << n2nc::sync::Thread::getCurrent().toString() << endl ;
00023 }
00024
00025 class myclass1 : public n2nc::sync::Thread {
00026 virtual void* entry_point(){
00027 cerr << "myclass1 callled with args: " << (char*)this->m_args ;
00028 cerr << " Thread name: " << n2nc::sync::Thread::getCurrent().toString() << endl ;
00029 sleep(6);
00030 return (void*)"myclass1" ;
00031 }
00032 virtual int exit_point(){
00033
00034
00035 g_sem.post();
00036 }
00037
00038 };
00039
00040 int main(int argc, char *argv[]){
00041 void *myretval1,*myretval2 ;
00042 n2nc::sync::Thread::init();
00043 n2nc::sync::Thread *t1 = new n2nc::sync::InlineThread(&fun1);
00044 n2nc::sync::Thread *t2 = new myclass1() ;
00045 n2nc::sync::Thread *t3 = new n2nc::sync::InlineThread(&fun1,&fun1_exit);
00046 t1->setName("fun1 thread name");
00047 t2->setName("myclass1 thread name");
00048 t3->setName("fun1 thread name, with exit point callback");
00049 t1->run((void*)"args to function fun1");
00050 t2->run((void*)"args to class myclass1");
00051 t3->run((void*)"args to function fun1 with callback");
00052
00053 g_sem.wait();
00054 g_sem.wait();
00055 g_sem.wait();
00056
00057
00058 cerr << (char*)t1->getRetVal() << endl ;
00059 cerr << (char*)t2->getRetVal() << endl ;
00060 cerr << (char*)t3->getRetVal() << endl ;
00061 return EXIT_SUCCESS;
00062 }