Dear All, I need some help with TThreads. I read the page at http://www-linux.gsi.de/~go4/HOWTOthreads/howtothreadsbody.html but I'm still lost. I wrote two pieces of code (They are at the end of the message). I am trying to use then outside CINT. To compile and link I did: g++ `root-config --cflags` -o test05.exe test05.cc `root-config --libs` -lThread And the application test05.exe is produced without any errors or warnings. The application also runs without errors but the "myThread->Run();" apparently is not working, because I do not see the output of the cout statements inside the function "doit". Could someone please help me? I am using ROOT v3.02/07. Thanks a lot, Sergio -------------------------------------------------------- // header file test05.h #include "TApplication.h" #include "TROOT.h" #include "TThread.h" #include <stream.h> class ThreadPar { public: int count; char *argv; ThreadPar() { count = 0; argv = NULL;} ~ThreadPar(); }; void *doit(void *myPar) { TThread::Lock(); cout << "Inside MyThread\n"; ThreadPar *myTPar = (ThreadPar *) myPar; if (myPar) { for(int i=0;i<=5;i++) { cout << myTPar->count << ", " << myTPar->argv << "===>" << i << endl; } }else { cout << "myPar is null.\n"; } TThread::UnLock(); return 0; } -------------------------------------------------------------------------- // test05.cc #include "test05.h" int main(int argc, char **argv){ ThreadPar *myThreadPar = new ThreadPar(); TThread *myThread = new TThread("MyThread",doit,(void *) myThreadPar); for (int j=0;j<argc;j++) { myThreadPar->count = j; myThreadPar->argv = argv[j]; cout <<"Calling MyThread " << j << '\t' << argv[j] << endl; myThread->Run(); } return 0; }
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:14 MET