Hi Volker! > can one do socket communication in a TThread, i.e. use TSocket? Yes, you can use TSockets in a TThread. We use it intensively for the Go4 framework http://go4.gsi.de/ (Go4TaskHandler library). However, you get into trouble if you try to _create_ a TServerSocket from within a running thread; a socket accepted by this serversocket instance might not be closed properly on deletion of the TSocket instance (such was my experience when I tested it with previous root versions). The linux tcp were not cleaned up after finishing the root session and kept in a FIN_WAIT state for hours! This is probably caused by the fact that the root socket instances are managed by the root TApplication::InnerLoop(), which does not know about sockets created in threads. Therefore it is better to create root socket connections outside the threads, e.g. in the ctor of a class, or in a root TTimer (i.e. in the scope of the TApplication loop). The existing TSocket can then be passed to a thread which works on it. > If yes, what actions have to be performed in locked state? I > tried to run the client-server example from the tutorials > with the server code in a TThread. The hclient.C was still > executed in two different root sessions as macro. > The whole thing starts fine, but after a while the root session > running the server process completely hangs. Do you still use the TMonitor::Select in the hserver.C? I guess this could be crucial, since the method invokes the gSystem->InnerLoop(), which can not be expected to work in several threads! Additionally, if you use root TMessage transport, be aware that here each TSocket::Receive(TMessage*) and TMessage::ReadObject creates objects and uses the root streamer, respectively. In general, I would suggest to TThread::Lock() all streamer usages and object instantiations in the different threads, if possible. However, you must not lock TSocket::Receive... Hope this helps, best regards Joern ///////////////////////////////////////////////////////////////////// // Dr. J"orn Adamczewski (J.Adamczewski@gsi.de) // // GO4 project team Tel: +49-06159-71-2554 // // Datenverarbeitung & ExperimentElektronik FAX: +49-06159-71-2986 // // Ges. f. SchwerIonenforschung, Planckstr.1, D-64291 Darmstadt //
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:04 MET