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!