carb::thread::futex::wait_until

Defined in carb/thread/Futex.h

template<class T, class Clock, class Duration>
inline bool carb::thread::futex::wait_until(const std::atomic<T> &val, T compare, const std::chrono::time_point<Clock, Duration> &time_point)

Waits on a value until woken or timed out.

The value at val is atomically compared with compare. 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.

Parameters
  • val – The value that is read atomically. If this matches compare, the thread sleeps.

  • compare – The expected value.

  • time_point – The absolute time point to wait until.

Returns

true if woken legitimately or spuriously; false if timed out.