TThread and new TF1

Hi,
I have two thread in my program. The main thread starts the second thread that calls a static function that in turn will call a class method that will calculate things. The class method gets a pointer where it will write how far the calculations has come. The main thread, after calling TThread::Run() of the newly created thread, then creates a dialog inheriting from TGTransientFrame that will update a progressbar using the above mentioned pointer (in a loop calling gSystem->Sleep(500)).

Now, the problem is that sometimes the calculation thread stops right before its supposed to create a TF1 object. I have tried with TThread::Lock()/UnLock() but that did not change anything. It seems like this only happends when I have created threads earlier in the execution of the program. However, if I after an execution of a “calculation-thread” start a new identical “calculation-thread” the thread stops even before the class method is called.

Here are some simplifyed parts of the code I use:

Starting new Thread and creating the progressbar dialog:

Double_t progress = 0; TThread thread("CalcThread",MyClass::runCalc,&progress); thread.Run(); new ProgressDialog(&progress);

The function runCalc:

void* PeakFindFitter::runCalc(void* args){ ptr_to_object->calc(static_cast<Double_t*>(args)); return 0;}

The loop updating the progressbar (inside ProgressDialog’s ctor):

while( *progress <= 1 ) { bar->SetPosition(*progress * 100); gClient->ProcessEventsFor(this); gClient->NeedRedraw(this); gSystem->Sleep(500); } this->CloseWindow();

I do not know much about how threads are implemented in ROOT so I’m hoping someone will see what’s wrong here.

Thanks in advance!

Merged into previous post

Hi,

[quote]Now, the problem is that sometimes the calculation thread stops right before its supposed to create a TF1 object. [/quote]If possible, I recommend that you create the TF1 in the main thread before starting the 2nd thread.

[quote]The problem is that sometimes the calculation thread stops right before its supposed to create a TF1 object… It seems like this only happends when I have created threads earlier in the execution of the program.[/quote]It sounds like you might be stumbling into one of the (hard to remove) deadlock that you we have not yet completely fixed.

Philippe.

I declared the TF1 static so that it would only be created once but that did not change anything. However by doing the calculations in the main thread and instead showing the progressbar in a new thread the problem can be worked around.

Just for curiosity: Do you have an idea of what is happening here?

[quote]Just for curiosity: Do you have an idea of what is happening here?[/quote]Yes and no. Apparently you ran into a ‘deadlock’ and we are aware of a few (hard to fix and hard to describe) ways to get into those. We are working on trying to resolve them but not before the next production release.

Cheers,
Philippe.