carb::thread::futex::wait

Defined in carb/thread/Futex.h

template<class T>
inline void carb::thread::futex::wait(const std::atomic<T> &val, T compare)

Waits on a value until woken.

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.