Re: [ROOT] deleting threads

From: Victor Perevoztchikov (perev@bnl.gov)
Date: Thu May 16 2002 - 23:52:29 MEST


Hi Sasha,
> Sometimes this happens at the second Start/Stop, sometimes later. If
anyone
> got experiences with TThread and could point me in the right direction, I
> would be really happy.

It coud be result of:
> if (!mcThread) { mcThread = new TThread("MonteCarlo", (void(*)
(void*))&MonteCarlo, (void*)this);

> mcThread->Run();

So if  mcThread already started you Run() it again. So you have 2 threads
for one class TThread.
I do not remember it was allowed intentionaly or by mistake.

Then you close one thread and do : mcThread=0
Redundunt thread still runing.



Victor M. Perevoztchikov   perev@bnl.gov
Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
tel office : 631-344-7894; fax 631-344-4206; home 631-345-2690

----- Original Message -----
From: <sascha.zelzer@gmx.net>
To: <roottalk@cern.ch>
Sent: Thursday, May 16, 2002 11:10 AM
Subject: [ROOT] deleting threads


> Hi!
>
> I am writing a GUI program which uses an extra thread to do a Monte-Carlo
> algorithm ( the function "void Layer::MonteCarlo(void*)" ). For this I've
got
> two buttons to start and stop the thread, each calling a specific
function:
>
> Int_t Layer::MonteCarloStart()
> {
> runSimulation = kTRUE;
> cout << "MonteCarloStart()" << endl;
> if (!mcThread) {
> mcThread = new TThread("MonteCarlo", (void(*) (void*))&MonteCarlo,
> (void*)this);
> cout << "[MonteCarloStart()] ThreadState: " << mcThread->GetState() <<
> endl;
> mcThread->Run();
> cout << "[MonteCarloStart()] ThreadState: " << mcThread->GetState() <<
> endl;
> return 0;
> }
>
> return 1;
> }
>
> Int_t Layer::MonteCarloStop()
> {
> runSimulation = kFALSE;
> TThread::Sleep(1);
> cout << "MonteCarloStop()" << endl;
>
> if (mcThread) {
> TThread::Delete(mcThread);
> if (mcThread) delete mcThread;
> cout << "[MonteCarloStop] thread deleted" << endl;
> mcThread = 0;
> return 0;
> }
>
> return 1;
> }
>
> If I do repeated Start/Stop sequences, it happens that the thread gets
> created and the Run() function is executed, but somehow the MonteCarlo()
function
> isn't. Then MonteCarloStop() won't delete the thread and it rests in
memory.
> Sometimes this happens at the second Start/Stop, sometimes later. If
anyone
> got experiences with TThread and could point me in the right direction, I
> would be really happy.
>
> I am using ROOT v3.02.07 and POSIX threads.
>
> Thanks,
> Sascha
>
> --
> GMX - Die Kommunikationsplattform im Internet.
> http://www.gmx.net
>



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:53 MET