Skip to content

Commit a688a03

Browse files
committed
Auto merge of #99505 - joboet:futex_once, r=thomcc
std: use futex in `Once` Now that we have efficient locks, let's optimize the rest of `sync` as well. This PR adds a futex-based implementation for `Once`, which drastically simplifies the implementation compared to the generic version, which is provided as fallback for platforms without futex (Windows only supports them on newer versions, so it uses the fallback for now). Instead of storing a linked list of waiters, the new implementation adds another state (`QUEUED`), which is set when there are waiting threads. These now use `futex_wait` on that state and are woken by the running thread when it finishes and notices the `QUEUED` state, thereby avoiding unnecessary calls to `futex_wake_all`.
2 parents eed7f2f + 5d0211d commit a688a03

File tree

5 files changed

+483
-289
lines changed

5 files changed

+483
-289
lines changed

0 commit comments

Comments
 (0)