Repository navigation
ThreadSafe: take the lock once in the constructor (MinGW test aborts) - #30
Merged
Merged
Conversation
After the MinGW toolchain update (GCC 16.2, new winpthreads) four test programs abort in Debug with shared_mutex:205: __shared_mutex_pthread::lock(): Assertion '__ret == 0' failed in the two tests that start several threads on a freshly constructed ThreadSafe<T>. The locking in those tests is ordinary: ten threads each taking the exclusive lock. winpthreads initialises a read-write lock lazily on first use, and concurrent first use can return an error rather than the lock; in a Release build that error is ignored and the lock is simply not held. Take and release the lock once in the constructor, before the object can be shared, so the lock is fully set up by the time other threads reach it. This is a workaround based on that reading of the failure; CI on the MinGW jobs is the test of it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011vmiZ7F3rQu7dith9sQw71
There was a problem hiding this comment.
🔵 Needs a closer look
The workaround relies on an unconfirmed winpthreads initialization diagnosis, requiring human validation of MinGW Debug stability and Release mutual exclusion on the affected MSYS2 UCRT64 toolchain because Linux coverage cannot establish either.
No open issues 🎉
What changed in this PR
Adds a constructor-time lock/unlock to the core ThreadSafe<T> wrapper as a workaround for suspected MinGW winpthreads initialization failures. The diagnosis remains unconfirmed pending Windows CI results.
Changes:
- Acquires and releases the mutex during construction, before the object is shared with other threads.
- Adds a comment explaining the suspected simultaneous-first-use failure.
| File | Description |
|---|---|
include/bolt/core/thread_safety.hpp |
Adds a constructor-scoped exclusive lock and documents the workaround’s rationale. |
Review effort: Balanced
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.
Description
One commit that was pushed just after #29 was merged, so it is not on
mainyet.Since the MinGW CI jobs moved to MSYS2's UCRT64 environment (GCC 16.2 and a new winpthreads, both updated by MSYS2 on 20 Nov), four test programs abort in the Debug job:
in
[Logging] ThreadSafetyand[E2E_ThreadSafety] ThreadSafe_ConcurrentAccess, the two tests that start several threads on a freshly constructedThreadSafe<T>.Type of Change
Related Issues
Related to #29
Changes Made
ThreadSafe<T>takes and releases its lock once in the constructor, before the object can be shared with other threads.The locking in the failing tests is ordinary (ten threads each taking the exclusive lock). winpthreads sets a read-write lock up lazily on first use; my reading of the failure is that simultaneous first use can return an error instead of the lock. In a Release build that error is ignored and the lock is simply not held, so this is not only a test problem. This is a workaround based on that reading, not a confirmed diagnosis: there is no Windows machine in my environment, and the MinGW jobs on this PR are the test of it.
Testing
Locally on Linux (GCC): 98/98 CTest tests. CI results for the MinGW jobs will be added here.
Generated by Claude Code