Skip to content

Implement bn::base::{mutex, recursive_mutex} for Windows and Linux - #8479

Open
bdash wants to merge 2 commits into
devfrom
test_compact_mutex_win_linux
Open

Implement bn::base::{mutex, recursive_mutex} for Windows and Linux#8479
bdash wants to merge 2 commits into
devfrom
test_compact_mutex_win_linux

Conversation

@bdash

@bdash bdash commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

On Windows, mutex wraps a std::shared_mutex, which unlike std::mutex is a thin wrapper around SRWLOCK, so it is both fast and compact.

On Linux, it is modeled after mutex3 from Drepper's "Futexes are Tricky". A std::atomic<int> holds the state, and blocking is handled via platform_wait, a thin abstraction over futex wait/wake that also has __ulock and WaitOnAddress backends for macOS and Windows.

recursive_mutex is a wrapper around mutex that tracks the owning thread and recursion count.

These are comparable in performance to the equivalent standard library types, but they're significantly smaller (on Windows 8 bytes vs 80, on Linux 4 bytes vs 40).

bdash added 2 commits August 27, 2026 08:34
On Windows, `mutex` wraps a `std::shared_mutex`, which unlike
`std::mutex` is a thin wrapper around `SRWLOCK`, so it is both fast and
compact.

On Linux, it is modeled after `mutex3` from Drepper's "Futexes are
Tricky". A `std::atomic<int>` holds the state, and blocking is handled
via `platform_wait`, a thin abstraction over futex wait/wake that also
has `__ulock` and `WaitOnAddress` backends for macOS and Windows.

`recursive_mutex` is a wrapper around `mutex` that tracks the owning
thread and recursion count.

These are comparable in performance to the equivalent standard library
types, but they're significantly smaller (on Windows 8 bytes vs 80, on
Linux 4 bytes vs 40).
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.

1 participant