carb::this_thread::spinTryWaitWithBackoff
Defined in carb/thread/Util.h
- 
template<class Func>
 bool carb::this_thread::spinTryWaitWithBackoff(Func &&f) noexcept(noexcept(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, and- fneeds to succeed (return- true) before continuing, but- fwill only succeed for one thread at a time. This function will call- finterspersed with increasing invocations of CARB_HARDWARE_PAUSE. However, unlike spinTryWait(), this function will then proceed to- std::this_thread::yield()calls which will typically enter the kernel to wait. After a certain number of attempts, the function gives up and returns- false. If- freturns- true, spinTryWait() immediately returns- true.- Note - This function may enter the kernel to wait. - Parameters
- f – The predicate to call repeatedly until it returns - true.
- Returns
- trueimmediately when- freturns- true. If a number of attempts to call- fall return- falsethen the function gives up and- falseis returned.