mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 09:25:01 +01:00
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. |
||
|---|---|---|
| .. | ||
| Mutex | ||
| Condition.zig | ||
| Futex.zig | ||
| Mutex.zig | ||
| RwLock.zig | ||
| Semaphore.zig | ||
| WaitGroup.zig | ||