Defined in carb/thread/Util.h

template<class Func>
bool carb::this_thread::spinTryWait(Func &&f) noexcept(noexcept(f()))

Calls a predicate until it returns true or a number of attempts have elapsed.

This function is recommended only for situations where exactly one thread is waiting on another thread. For multiple threads waiting on a predicate, use spinTryWaitWithBackoff().

This function will call f interspersed with increasing invocations of CARB_HARDWARE_PAUSE. After a certain number of attempts, the function gives up and returns false. If f returns true, spinTryWait() immediately returns true.


This function does not enter the kernel to wait.


f – The predicate to call repeatedly until it returns true.


true immediately when f returns true. If a number of attempts to call f all return false then the function gives up and false is returned.