Home | News | Documentation | Download

Issue with TF1 in multithreaded application


I have a multithreaded application (Geant4) that creates a new TF1 object in each worker thread. Invoking for example:

new TF1("test", "1", 0, 2);

However for some reason I cannot have more than one worker thread contruct this object or it will throw a strange error message:

input_line_13:2:10: error: expected '{'
input_line_13:2:10: error: C++ requires a type specifier for all declarations
Double_t TFormula____id10159970873491820195(){ return 1 ; }
Double_t TFormula____id10159970873491820195(){ return 1 ; }
 *** Break *** segmentation violation
error: expected unqualified-id
Double_t TFormula____id10159970873491820195(){ return 1 ; }

 *** Break *** segmentation violation

My guess is that it has something to do with the global state, perhaps there is something trivial I am missing since I don’t usually work with this classes. Thanks.

ROOT Version: 6-25-01

The problem is fixed by calling


from the #include <TROOT.h> header.

1 Like

Thank you for posting the solution.
This is correct, if you don’t call ROOT::EnableThreadSafety() the locks for the usage of the interpreter in the parsing of the Formula used in TF1 are not enabled.



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