# std.Io.Threaded: make parking_futex lock-free · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/2bc89a5198eeb8b598c76ae18b1813616a330b5b)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 2bc89a5198eeb8b598c76ae18b1813616a330b5b

Requested commit: 2bc89a5198eeb8b598c76ae18b1813616a330b5b

Commit: 2bc89a5198eeb8b598c76ae18b1813616a330b5b

Tree: a45032afa515203315d18cdcec37b05fa1142b4a

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
std.Io.Threaded: make parking_futex lock-free

And therefore no longer depend on a mutex API.

The idea here is to rely on cache line operations being very fast.
Buckets span exactly one cache line each, storing only waiter pointers.
Additions and removals do linear weak cmpxchg scan over the cache line,
repeating until sucess.

If there are more parked threads with bucket hash collisions than fits
into a cache line then wait() degrades into a spin lock.

```

## Parents

- [e9eadee00654f5f762abe3cdc596359b79893eab](https://git.cafe/gitcafe/zig/commit/e9eadee00654f5f762abe3cdc596359b79893eab?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/2bc89a5198eeb8b598c76ae18b1813616a330b5b?format=markdown)
