Re: How to stop properly a TServerSocket running in a TThread

From: Fons Rademakers <Fons.Rademakers_at_cern.ch>
Date: Tue, 06 Feb 2007 15:16:57 +0100


Your thread was started using a VoidFunc_t and can this not be joined when finished, hence the error at Join().

Cheers, Fons.

Legeard Luc wrote:

> Leandro Franco wrote:
> 

>>
>> By the way...
>>
>>
>> I saw a couple of problems when you clean up the objects... something
>> like this should be more convenient:
>>
>>
>>
>>
>> //_________________________________________________________________________________________
>>
>> ServerRoot::ServerRoot()
>> { fRunning=false; fSockList=NULL;
>> fThreadNet=NULL;
>> fServSock=NULL;
>> fHisto = NULL;
>> fStarting=false;
>> fMon = new TMonitor;
>> }
>> //_________________________________________________________________________________________
>>
>> ServerRoot::~ServerRoot()
>> { // desctructor StopGNetServer();
>>
>>
>> if (fMon)
>> delete fMon;
>> }
>> //_________________________________________________________________________________________
>>
>> void ServerRoot::StopGNetServer ()
>> {
>> // Stop the Network server if (fRunning==false) {
>> cout<<"Server already stopped\n";
>> return;
>> }
>>
>>
>> if(fThreadNet) { fRunning = false; fThreadNet->Join();
>> //TThread::Delete(fThreadNet);
>> //delete fThreadNet; fThreadNet=NULL;
>> cout<<"\n\t*********************\n\t Net Server
>> stopped\n\t*********************\n";
>> }else{ cout <<" Thread no present\n";
>> }
>>
>>
>> fMon->RemoveAll();
>>
>>
>> if (fServSock) {
>> delete (fServSock);
>> fServSock=NULL;
>> } if (fSockList) { fSockList->Delete();
>> delete (fSockList);
>> fSockList=NULL;
>> }
>> }
>>
>>
>>
> Thanks a lot,
> Now root doesn't crash anymore,
> but a error message appears :
> 
> 
> root [9]  serv ->StopGNetServer();
> Error in <Join MESSAGE_Net_Server:0xb7fa1bb0>: cannot join detached thread
> 
> if I comment the line   > "fThreadNet->Join();"
> it works also without error message and seems to works fine
> Moreover I don't really undestand the meaning of this line !
> 
> Luc
> 

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers_at_cern.ch              Phone: +41 22 7679248
WWW:    http://fons.rademakers.org           Fax:   +41 22 7669640
Received on Tue Feb 06 2007 - 15:16:49 CET

This archive was generated by hypermail 2.2.0 : Wed Feb 07 2007 - 11:50:01 CET