I’ve been working trying to integrate some some code that uses ROOT into a Node.js framework, which necessitates use of threads. Based on Multicore/multithreading, I’m explicitly keeping all ROOT operations confined locally to their own threads.
However, my test case keeps exploding. I have some rather complicated LarSOFT framework code, but at it’s heart it’s doing this (all in one thread):
tree = f.Get(“tree”);
This code creates a lot of side activity, requiring a lot of environment variables and other shared libraries. However, it fails at the GetEntry() call.
Now here’s the interesting thing:
It runs fine if the main thread calls my_thing()
It runs fine if my_thing() is in a sub-thread (with no other activity) as long as EnableThreadSafety() is NOT called.
If I call EnableThreadSafety in the main thread, and then call my_thing(), it segfaults.
(I get: “Warning in TClass::GetStreamer: For art::BranchDescription, the TClassStreamer passed does not properly implement the Generate method”, followed by the crash dump) The debugger says it’s crashing in one of the framework libraries, in a TClassStreamer::operator() method.
If I don’t call EnableThreadSaftety(), and attempt a simultaneous my_thing() in another thread, it crashes… as expected from the discussion of ROOT internals.
If I launch both my_thing() calls from different threads, but non-simultaneous, with EnableThreadSafety() off, everything works OK.
The puzzling thing is why EnableThreadSaftety() would cause problems…? My guess was that the first launch of the my_thing code causes a lot of shared libraries to get loaded only in that particular thread. But I tried launching my_thing() from the main thread, letting it finish, and then launching it from a thread… and the thread crashes again.
I’m at my wits end here. I can’t figure out how my_thing() even KNOWS it’s in a thread!
(To those who say “don’t do this”… I’m trying to build a server that can reply to multiple data requests via http. Those requests are time-consuming, and so require either a new executable launch, a new fork, or a new thread for each request.)
ROOT Version: 6.12/06