Crates.io | atomic-wait |
lib.rs | atomic-wait |
version | 1.1.0 |
source | src |
created_at | 2022-09-16 20:49:14.851062 |
updated_at | 2023-01-02 13:17:54.448185 |
description | Cross-platform atomic wait and wake (aka futex) functionality. |
homepage | |
repository | https://github.com/m-ou-se/atomic-wait |
max_upload_size | |
id | 667705 |
size | 12,387 |
Cross platform atomic wait and wake (aka futex) functionality.
This crate only supports functionality that's available on all of Linux, FreeBSD, Windows, and macOS. That is:
AtomicU32
is supported.
(Linux currently only supports 32-bit futexes.)Supported platforms: Linux 2.6.22+, FreeBSD 11+, Windows 8+, Windows Server 2012+, macOS 11+, iOS 14+, watchOS 7+.
use std::sync::atomic::AtomicU32;
use atomic_wait::{wait, wake_one, wake_all};
let a = AtomicU32::new(0);
wait(&a, 1); // If the value is 1, wait.
wake_one(&a); // Wake one waiting thread.
wake_all(&a); // Wake all waiting threads.
On Linux, this uses the SYS_futex
syscall.
On FreeBSD, this uses the _umtx_op
syscall.
On Windows, this uses the WaitOnAddress
and WakeByAddress
APIs.
On macOS (and iOS and watchOS), this uses libc++
, making use of the same
(ABI-stable) functions behind C++20's atomic_wait
and atomic_notify
functions.