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 returns false. If f returns true, spinTryWait() immediately returns true.

Note

This function does not enter the kernel to wait.

Parameters

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

Returns

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.