carb::thread::futex::wait_for
Defined in carb/thread/Futex.h
-
template<class T, class Rep, class Period>
inline bool carb::thread::futex::wait_for(const std::atomic<T> &val, T compare, const std::chrono::duration<Rep, Period> &duration) Waits on a value until woken or timed out.
The value at
val
is atomically compared withcompare
. If the values are not equal, this function returns immediately. Otherwise, if the values are equal, this function sleeps the current thread. Waking is not automatic when the value changes. The thread that changes the value must then call wake() to wake the waiting threads.Note
Futexes are prone to spurious wakeups. It is the responsibility of the caller to determine whether a return from wait() is spurious or valid.
Note
On Linux, interruptions by signals are treated as spurious wakeups.
- Parameters
val – The value that is read atomically. If this matches
compare
, the thread sleeps.compare – The expected value.
duration – The relative time to wait.
- Returns
true
if woken legitimately or spuriously;false
if timed out.