spinWaitWithBackoff#
Fully qualified name: carb::this_thread::spinWaitWithBackoff
Defined in carb/thread/Util.h
-
template<class Func>
void carb::this_thread::spinWaitWithBackoff( - Func &&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 invokestd::this_thread::yield()between calls tof. This is a back-off mechanism to allow one thread to move forward while other competing threads wait their turn.Note
This function does not return until
fhas returnedtruefor the calling thread. For a version of this function that will give up, use spinTryWaitWithBackoff().Note
This function may enter the kernel to wait.
- Parameters:
f – The predicate to call repeatedly until it returns
true.