spinTryWaitWithBackoff#
Fully qualified name: carb::this_thread::spinTryWaitWithBackoff
Defined in carb/thread/Util.h
-
template<class Func>
bool carb::this_thread::spinTryWaitWithBackoff( - Func &&f,
Calls a predicate until it returns true or a number of attempts have elapsed, backing off as time passes.
This function is a low-level utility for high-contention cases where multiple threads will be calling
fsimultaneously, andfneeds to succeed (returntrue) before continuing, butfwill only succeed for one thread at a time. This function will callfinterspersed with increasing invocations of CARB_HARDWARE_PAUSE. However, unlike spinTryWait(), this function will then proceed tostd::this_thread::yield()calls which will typically enter the kernel to wait. After a certain number of attempts, the function gives up and returnsfalse. Iffreturnstrue, spinTryWait() immediately returnstrue.Note
This function may enter the kernel to wait.
- Parameters:
f – The predicate to call repeatedly until it returns
true.- Returns:
trueimmediately whenfreturnstrue. If a number of attempts to callfall returnfalsethen the function gives up andfalseis returned.