carb::this_thread::spinWaitWithBackoff
Defined in carb/thread/Util.h
-
template<class Func>
void carb::this_thread::spinWaitWithBackoff(Func &&f) noexcept(noexcept(f())) Calls a predicate until it returns true with progressively increasing delays between calls.
This function is a low-level utility for high-contention cases where multiple threads will be calling
fsimultaneously,fneeds to succeed (returntrue) before continuing, butfwill only succeed for one thread at a time. This function does not return untilfreturnstrue, at which point this function returns immediately. High contention is assumed whenfreturnsfalsefor several calls, at which point the calling thread will progressively sleep between bursts of calls tof. This is a back-off mechanism to allow one thread to move forward while other competing threads wait their turn.- Parameters
f – The predicate to call repeatedly until it returns
true.