When trying to join the 0-th thread I’m getting an error:
joining 0 thread...
terminate called after throwing an instance of 'std::system_error'
what(): Invalid argument
Another problem is that I somehow cannot use ROOT::EnableThreadSafety(), getting an error, saying there is no such func in ROOT namespace.
As possible solution tried to preload libthread.so, which did not help.
Would be grateful for any hint on the solution to this.
Cheers,
Ivan
Hi Ivan,
note that @behrenhoff code introduces int arg = trd; which is not present in your original code making the lambda capture ill-formed.
ROOT::EnableThreadSafety is available for all installations of ROOT built with the -Dimt=ON option (which is the default since at least v6.10, as far as I know). Of course you also need #include "ROOT.h" to have the declaration available.
Why is it ill-formed? Could you give a hint which rule I am violating here? The variable arg was already in the original code, I had to define it somehow.
Thanks for replies.
Dear behrenhoff, your code works fine. As the most probable source of the problem, I’m now trying to figure out the problem in my function.
This is actually quite cumbersome function, calculating few matrix elements and thus operating complex floats.
Dear eguiraud, thanks for your remark. My agr-s were properly defined, I just did not include that piece of code in my post.
As soon as I figure out the problem, I’ll respond here.
Thanks again!
Ivan
I’d try to use a gloabl std::mutex dangerousRootMutex; and then start locking suspicious code using a std::lock_guard<std::mutex> lock(dangerousRootMutex); - for example, protect everything that works with global variables like gDirectory. (and find a better name for dangerousRootMutex)
Is there any documentation which functions are protected by ROOT::EnableThreadSafety? I tend to put a lock_guard around everything unless I know for sure that it is thread safe.
Ok, concerning original question. I managed to make things work.
The bug was stupid but not evident (as it is usual)):
one of the function parameters depends on the thread number and due to a typo in different program, this parameter ran out of it’s boundaries.
behrenhoff, eguiraud, thanks a lot for sparing your time on my problem!