-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread-safety #28
Comments
Hi Luigi, |
As reported in BxCppDev#28, bxdecay0 can produce segfaults when running as the primary generator of a multithreaded Geant4 application. Triaged in this use case to the use of statics in the pattern: ``` some_t function() { static thing_t thing; if (thing.not_init()) thing.fill(); ... return thing; } ``` Whilst C++11 guarantees the initialization of `thing` to be thread safe (at least for standard types), the code following the init statement is not. For example, a vector could be initialzed then filled if empty, but multiple threads could contend over the scope that does the filling. Decouple static initialization by factoring the filling of the static objects into separate functions. As the initialization of the static is only called once, so is the initialization function and thus removing thread contention issues. Note that the BinReloc functions are not modified using this pattern, but as the calls to these functions are only in bxdecay0::get_library_dir() and its init function, these should be sufficiently protected. At worst a lock_guard is needed in this one place.
I think this issue can be closed. Tried with a current build of remage, and no crashes can be observed. The "remaining thread-safety segfault" in remage described in #29 was probably another bug there, that I already fixed some time ago, so not of concern for BxDecay0. |
I was wondering whether BxDecay0 is thread-safe. I have tried embedding it in my GEANT4 application (by using the built-in extension) and it works fine in sequential mode, but segfaults in multi-threaded mode. The stack trace is never the same (symptom of some non-deterministic race condition), but seems to point to a problem in
libBxDeca0.so
. For example:Still I could have messed it up somewhere else in my application – I was just wondering whether you can make a statement about thread safety in general.
The text was updated successfully, but these errors were encountered: