LHAPDF is not thread safe
The original description of this Issue is below, but the problem is not limited to the PDF cache, but instead it's everywhere where a static local variable (local variable with a static
modifier in a function or method) is used. The fix is very simple though: replace static
with static thread_local
. See also merge request !3 (closed).
I am using LHAPDF 6.3.0 in a multi-threaded environment and I've discovered that at least the following line isn't thread safe (it segfaults in my application):
https://gitlab.com/hepcedar/lhapdf/-/blob/master/src/LogBicubicInterpolator.cc#L154
When _getQ2CachesMap
is called for the first time with the given thread id, this line will add an element to the map (write access), which triggers a race condition with other threads writing to the map.
To fix this problem one has to lock the write access, although that might be expensive and defeat the purpose of the cache.