Two TSocket instances in two threads will conflict?


I m trying to develop a root based application, which need two TSockets, each socket is responsible for receiving TMessages from a server, and when I put each socket in a separate thread it gives error (please see the following), but when I put it in a separate process it doesn’t!

The error message appears randomly, not immediately upon starting the run.

I guess two sockets running in the same process will conflict, what is the correct way to do it?

Can someone help?

Thanks a lot.


error info:
 *** Break *** segmentation violation
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
#6  0x00007f1ee9fd56e4 in TClass::StreamerTObjectInitialized(TClass const*, void*, TBuffer&, TClass const*) () from /opt/root/lib/
#7  0x00007f1ee91d2bef in TGenCollectionStreamer::WriteObjects(int, TBuffer&) () from /opt/root/lib/
#8  0x00007f1ee919f978 in TCollectionStreamer::Streamer(TBuffer&, void*, int, TClass*) () from /opt/root/lib/
#9  0x00007f1ee9147aeb in TBufferFile::WriteFastArray(void*, TClass const*, int, TMemberStreamer*) () from /opt/root/lib/
#10 0x00007f1ee93d71c4 in int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) () from /opt/root/lib/
#11 0x00007f1ee9222ab4 in TStreamerInfoActions::GenericWriteAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /opt/root/lib/
#12 0x00007f1ee914d6d5 in TBufferFile::WriteClassBuffer(TClass const*, void*) () from /opt/root/lib/
#13 0x00007f1ee906949f in RawEvent::Streamer (this=0x7f1ee3c6e960, R__b=...) at /storage/ATTPC/DAQ/build/src/RawEvent/RawEvent_dict.cxx:221
#14 0x00007f1ee914cdbb in TBufferFile::WriteObjectClass(void const*, TClass const*, bool) () from /opt/root/lib/
#15 0x00007f1ee91544cf in TBufferIO::WriteObjectAny(void const*, TClass const*, bool) () from /opt/root/lib/
#16 0x00007f1eea315680 in TBuffer::WriteObject<RawEvent> (this=0x7f1eab4e57b0, objptr=0x7f1ee3c6e960, cacheReuse=true) at /opt/root/include/TBuffer.h:414
#17 0x00007f1eea314224 in TMessageBufferTP<RawEvent>::put (this=0x7f1e81ea5390, obj=0x7f1ee3c6e960) at /usr/local/include/TMessageBufferTP.h:53
#18 0x00007f1eea310046 in DataProcessor::rawEventProcess (this=0x55ff6919b450, ptrArray=0x7f1ee3c6aad0, fileID=69) at /DAQ/src/DataProcessor/DataProcessor.cpp:239

_ROOT Version: 6.26/04
_Platform: 22.04.1-Ubuntu x86_64 GNU/Linux
_Compiler: c++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0


Welcome to the ROOT community! Thanks for posting your question.
Could you provide a minimal reproducer?


Did you turn on thread support by calling:


? (4.5 KB)

Hi Danilo,


The attached file is a minimal reproducer.


I tried. But get different error.

What is the new error?

Dear Bing,

Thanks. I will get to this in 24 hours.


Great, the ROOT::EnableThreadSafety() make my code work. In my previous try, I put this function in a wrong place. Now, it works.

Thank you.

Hi Danilo,

With Ppcanal’s reminder, ROOT::EnableThreadSafety() solved the problem, thanks again!


1 Like

Sorry I was not clear:

  • ROOT::EnableThreadSafety() is compulsory to use ROOT code from multiple threads
  • It needs to be called before any threads is started.


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.