Issues with TThread

Hi,

I have 2 issues with threads in ROOT, especially with TThreads:

(1) To my understanding, the only way to make ROOT thread safe is to use at least one TThread. It would be nice to have another way to tell ROOT to be reentrant, e.g. by something like gROOT->SetReentrant(kTrue).

(2) I was using the static method TThread::Delete(TThread *&th), essentially following section 6.1 of http://www-linux.gsi.de/~go4/HOWTOthreads/howtoframe.html. However, my program crashed randomly. By reading the code, I found out that this interface has an ugly feature: if the thread is still running (kRunningState), the thread object is untouched, i.e. needs to be deleted in the user code as documented. However, if the thread has terminated by itself, the CleanUp() method is called which deletes the thread object, leaving a dangling pointer in the user code.

Remi

Hi Remi,

concerning 1) yes that is true. I’ll see if I can make TThread::SetReentrant().

concerning 2) I’ll investigate

Cheers, Fons.

Hi Remi,

I’ve added TThread::Initialize() to initialize the ROOT mutexes without the need to create a thread.

Concerning issue 2), it looks like that if you cal TThread::Delete(&mythread) that the mythread pointer will be zeroed in the mythread dtor. Idem when the running thread is first cancelled and then deleted later (the mythread pointer will be remembered in the fHolder data member.

Cheers, Fons.