Futexes v0.1.0

Source
Waiting on a word and waking its waiters through futex.

FutexWaitPrivate

pub const FutexWaitPrivate: int32 = 128;

FUTEX_WAIT_PRIVATE: sleep while the word holds the expected value.

Source

FutexWakePrivate

pub const FutexWakePrivate: int32 = 129;

FUTEX_WAKE_PRIVATE: wake threads sleeping on the word.

Source

FutexWait

pub func FutexWait(
    address: *uint32,
    expected: uint32,
    timeout: *Timespec
) -> int64

Sleeps while *address equals expected, until a wake, a signal or the timeout. Returns at once with -EAGAIN when the word already differs, which is how a caller learns it changed.

See also: https://man7.org/linux/man-pages/man2/futex.2.html

Source

Parameters

NameTypeDescription
address*uint32the word to wait on, four-byte aligned
expecteduint32the value the caller last saw there
timeout*Timespechow long to wait at most, relative to now, or null to wait without a limit

Returns: zero after a wake, or a negative error number: EAGAIN, EINTR or ETIMEDOUT

FutexWake

pub func FutexWake(address: *uint32, count: int32) -> int64

Wakes up to count threads sleeping on address.

See also: https://man7.org/linux/man-pages/man2/futex.2.html

Source

Parameters

NameTypeDescription
address*uint32the word they wait on
countint32how many to wake at most

Returns: how many were woken, or a negative error number