zig/lib/std/Thread
Matthew Lugg 4f16e80cea std: halve the number of mutexes per mutex
On NetBSD and Illumos, we were using the `std.Thread.Futex`-based
implementation of `std.Thread.Mutex`. But since futex is not a primitive
on these targets, the implementation of `std.Thread.Futex` was based on
pthread primitives, including `pthread_mutex_t`. This had the amusing
consequence that locking a contended mutex on NetBSD would actually
perform 2 mutex locks, 2 mutex unlocks, and 1 condition wait; likewise,
unlocking a contended mutex would perform 2 mutex locks, 2 mutex
unlocks, and 1 condition signal. Having read some cutting-edge studies,
I have concluded that this is a slightly suboptimal approach. Instead,
let's just use pthread mutexes directly in this case; that's an
obviously better idea.

In the future, I think we can probably entirely remove our usages of
pthread sync primitives---no platform actually treats them as the base
primitives. Of the platforms which std has any meaningful support for
today, most support futexes, and the exceptions (NetBSD and Illumos)
support a thread parking API. We can implement futex and/or mutex on top
of thread parking and drop the pthread dependency entirely.
2026-01-15 05:28:11 +01:00
..
Mutex std.Thread.Mutex.Recursive: alternate implementation 2024-06-12 18:07:39 -07:00
Condition.zig std.os.windows: eliminate forwarder function in kernel32 (#25766) 2025-10-31 13:54:50 +00:00
Futex.zig Fixes doc comment of Futex.wait 2025-12-27 20:40:19 +01:00
Mutex.zig std: halve the number of mutexes per mutex 2026-01-15 05:28:11 +01:00
RwLock.zig std: make RwLock test less intensive 2025-10-18 09:28:43 +01:00
Semaphore.zig Change many test blocks to doctests/decltests 2024-02-26 15:18:31 -08:00
WaitGroup.zig std.Io.Threaded: slightly different semantics 2025-11-21 19:54:41 -08:00