Skip to content

ThreadSafe: take the lock once in the constructor (MinGW test aborts) - #30

Merged
drzo merged 2 commits into
mainfrom
claude/loving-archimedes-r7fcwy
Nov 20, 2026
Merged

drzo merged 2 commits into
mainfrom
claude/loving-archimedes-r7fcwy

Conversation

@drzo

@drzo drzo commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Description

One commit that was pushed just after #29 was merged, so it is not on main yet.

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:

shared_mutex:205: void std::__shared_mutex_pthread::lock(): Assertion '__ret == 0' failed.

in [Logging] ThreadSafety and [E2E_ThreadSafety] ThreadSafe_ConcurrentAccess, the two tests that start several threads on a freshly constructed ThreadSafe<T>.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

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

  • All existing tests pass

Locally on Linux (GCC): 98/98 CTest tests. CI results for the MinGW jobs will be added here.


Generated by Claude Code

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
@drzo
drzo marked this pull request as ready for review November 20, 2026 14:09
Copilot AI balanced review requested due to automatic review settings November 20, 2026 14:09
@drzo
drzo merged commit 72221f9 into main Nov 20, 2026
47 of 48 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants