carb::this_thread::spinTryWait
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 returnsfalse
. Iff
returnstrue
, spinTryWait() immediately returnstrue
.Note
This function does not enter the kernel to wait.
- Parameters
f – The predicate to call repeatedly until it returns
true
.- Returns
true
immediately whenf
returnstrue
. If a number of attempts to callf
all returnfalse
then the function gives up andfalse
is returned.