ROOT 4.22 and OpenMP

Hi there,

I would like to fill one histogram object from 2 different threads. In my application threads are created via OpenMP.
The histogram object is being created by the first thread, which also is the master thread in the OpenMP thread team consisting of 2 threads. The calls of the fill()-method from the 2 threads on the histogram object are synchronized (via the OpenMP pragma critical). When the second thread calls the fill() method, the program ends up with a stack-overflow. See attachment stack_overflow1.jpg.

A very similar problem arised, when I tried to fill thread-local histograms first and get them merged (through TH1::merge) to a shared histogram afterwards. The stack-overflow problem arises when the second thread calls the fill() method on its local histogramm. See attachment stack_overflow2.jpg.

I understood that the ROOT libraries are not threadsafe, but is using different threads actually a problem? Why can’t a shared object be used from within different threads in a synchronized way? Is there some special initialization/environment needed, do I need some special version of ROOT?

I’m using ROOT 4.22 on a Windows XP machine and Visual Studio 2008 for software development.

Thanks in advance for your help.
stack_overflow.zip (200 KB)

Hi,

Using threads with ROOT requires proper locking mechanism (TThread::Lock()/TThread::UnLock()) to modify objects, e.g. filling histograms.
See for example $ROOTSYS/test/threads.cxx, a good example of how to use threads with ROOT, being also fully cross-platform. I can’t help with OpenMP, but the internal thread locking mechanism works using TThread, and is not aware of any other threading tool.

Cheers, Bertrand.