BUG: Make H5SUPPORT_MUTEX_LOCK a real process-wide HDF5 lock#1643
Open
joeykleingers wants to merge 2 commits into
Open
BUG: Make H5SUPPORT_MUTEX_LOCK a real process-wide HDF5 lock#1643joeykleingers wants to merge 2 commits into
joeykleingers wants to merge 2 commits into
Conversation
imikejackson
left a comment
Contributor
There was a problem hiding this comment.
Inline notes below. The singleton design (out-of-line SIMPLNX_EXPORT ApiLock(), leaky Meyers init) is the right mechanism and well-justified. My main concern is that, as it lands on develop, runtime behavior is unchanged because the macro is gated behind a define that is never set in this build — details inline.
Contributor
Review checklistTracking items from the inline review above. The singleton design itself is sound — these are the gaps before merge. Blocking
Non-blocking
🤖 Generated with Claude Code |
H5SUPPORT_MUTEX_LOCK() declared a fresh function-local std::mutex on every expansion and immediately locked it, so it provided no mutual exclusion across calls or threads (and expanded to nothing when H5Support_USE_MUTEX was undefined). The four HDF5 helpers that use it (IsGroup, GetObjectPath, GetDatasetType, StringForHDFType) were therefore unsynchronized against the non-thread-safe HDF5 C library. Add a single process-wide ApiLock() and point the macro at it. ApiLock is a plain std::mutex (an audit found no path re-acquires it while held, so it fails fast on accidental future re-entry); its contract — lock only leaf H5 calls, never hold across a helper that re-locks — is documented at the declaration. It is intentionally leaked so a teardown HDF5 call during static destruction cannot lock a destroyed mutex. The test drives the macro from many threads and asserts no lost updates. Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
* Define H5Support_USE_MUTEX PUBLIC on the simplnx target so the four macro-guarded HDF5 helpers actually serialize on the shared ApiLock() instead of the macro compiling to nothing. PUBLIC also propagates the define to simplnx_test, so the ApiLock regression guard runs live rather than taking the SUCCEED() no-op path. * Remove the nonexistent probeSingleDeflateEligibility reference from the ApiLock() doc comment and add a SCOPE note that only those four helpers are guarded (other direct H5* calls are not yet serialized). Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
b1805bf to
66eeebc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
H5SUPPORT_MUTEX_LOCK()declared a fresh function-localstd::mutexon everyexpansion and immediately locked it, so it provided no mutual exclusion across
calls or threads (and expanded to nothing when
H5Support_USE_MUTEXwasundefined). The four HDF5 helpers that use it (
IsGroup,GetObjectPath,GetDatasetType,StringForHDFType) were therefore effectively unsynchronizedagainst the non-thread-safe HDF5 C library.
ApiLock()(a leaky Meyers singleton) and point themacro at it.
H5Support_USE_MUTEXfor thesimplnxtarget(
target_compile_definitions(simplnx PUBLIC ...)) so the macro is actuallyengaged rather than compiled out.
PUBLICalso propagates the define tosimplnx_test, so the regression guard runs live instead of taking theSUCCEED()no-op path.asserts no lost updates (guards against reintroducing the per-call-local-mutex
bug).
Scope / caveats
calls on one mutex. It trades some HDF5-call concurrency for correctness against
the non-thread-safe vcpkg HDF5 build.
many other direct
H5*calls throughoutFileIO,DatasetIO, andDream3dIOare not yet serialized by it, so this does not by itself closethe broader HDF5 thread-safety story — it gives the rest of the code a single
lock to adopt as it is hardened.
Test Plan
simplnx_testHDF5 suite passes with the lock enabled (H5 Utilities,DatasetIO, HDF5ImplicitCopy, the ApiLock regression guard, Read Legacy
DREAM3D-NX Data, Contains HDF5 IO Support)