Fix race condition in PDF cache
This merge request fixes the problem I reported in issue #2 (closed). It locks the caches only when needed (when an element needs to be added to the map) and otherwise gives lock-free access. I also checked that there's no noticeable slowdown after applying the patch in my use case (spends most of the time in LHAPDF). It uses the thread_local
keyword to get a separate cache for each thread, which fixes all the problems I encountered. Commit 49c2cfeb fixes a similiar problem in PDFSet
.
What is missing from this patch is to protect the access to the maps inside LogBicubicInterpolator::Q2Caches::setup
and LogBicubicInterpolator::XCaches::setup
which both call clear()
. If the setup
functions are called in different threads this is not thread-safe.