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

From: Legeard Luc <legeard_at_ganil.fr>
Date: Tue, 06 Feb 2007 14:54:54 +0100


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

-- 
 ------------------------------------------------------------
 -  Luc LEGEARD                  - Tel   : 02 31 45 44 36   -
 -  GANIL  BP 55027 Bd Becquerel - Fax   : 02 31 45 47 97   -
 -  14076 CAEN Cedex 5           - mailto:legeard_at_ganil.fr  -
 -  Web http://www.ganil.fr
Received on Tue Feb 06 2007 - 14:55:03 CET

This archive was generated by hypermail 2.2.0 : Tue Feb 06 2007 - 17:50:01 CET