Stop TThread's by Joining the waiting main thread

Hi colleagues

Stopping TThread’s is one of the most annoying things for me. All techniques in the Documentation that I could found failed. Also some intuitive things. I tried it on a hundred different ways without succes. With pthreads I had never such problems by using the Join functionallity. In TThread’s my main thread is now still running after Joining through the help of this TJoinHelper class.

How can I do it properly? By the way, I have not jet found an example which is not craching on my machine if I reduce the sleeping time in the end of the thread. E.g. the example in ROOT 5.26-00b in the tutorial directory will crash too if you reduce the sleeping time to 100. The same example is running with pthread till 1 without problems. The Pi example from 2001 is also not running simply.

I just wanna start threads and let them join in case they are finished. The main thread should wait. Everything has to fit in a C++ environment, but this is not the problem.

Thx, Stefan

Hi Stefan,

Which example? There are three examples in the thread directory, and all of them are working properly for me, even if I reduce all the Sleep() calls to 1 (at least on Windows and SLC4, with svn trunk). Which OS/version are you working on?

Cheers, Bertrand.


sorry, the first one “threads.C”. Indeed I see that on SLC5 it’s not crashing but on my machines (Ubuntu 9&10) now always, nevertheless the same example with pthreads are working. I have root compiled with GCC 4.4+ but did not tried the trunk.

My root configuration is:

–with-pythia6-uscore=SINGLE --with-f77=gfortran --enable-roofit --enable-minuit2 --with-alien-incdir=… --with-alien-libdir=… --with-monalisa-libdir=… --with-monalisa-incdir=… --with-xrootd-incdir=… --with-xrootd-libdir=… --disable-editline --enable-gsl-shared --disable-globus --build=debug

the differences to SLC5 is just: monalisa, xrootd, editline, gsl-shared and globus and debug

The kind of crash is quite random. Here one example:

#2 0x00007fe88b81a441 in TUnixSystem::DispatchOneEvent (this=0x12d76e0, pendingOnly=)
at core/unix/src/TUnixSystem.cxx:961
#3 0x00007fe88b799106 in TSystem::InnerLoop (this=0x1) at core/base/src/TSystem.cxx:393
#4 0x00007fe88b79b2eb in TSystem::Run (this=) at core/base/src/TSystem.cxx:343
#5 0x00007fe88b73c6ff in TApplication::Run (this=0x1321d00, retrn=224) at core/base/src/TApplication.cxx:993
#6 0x00007fe88a5e7419 in TRint::Run (this=, retrn=224) at core/rint/src/TRint.cxx:438
#7 0x00000000004011bc in main (argc=1, argv=0x7fffe4b50f98) at main/src/rmain.cxx:29

But also simple break segmentation and some memory error crashes.

By the way I managed to use my Application without errors, just by deleting all deletes of thread related data. Somehow suspicious cause of some of them the thread doesn’t know about. I currently do not use the Joining functionality any more cause the main thread is still running and it’s hence not useful for me. Instead I made some complex waiting loop. Is here any easy solution?

Well, it is hard to tell without knowing what is the exact problem, what you mean by “complex waiting loop”, and without any piece of code (it may be related to what you do in your threads…)
– Bertrand.