What does a higher number of unsuccessful tries mean in a lock? what should it do incase of a backoff?
There is high contention
backoff longer
Lock-step
When all threads backs off the same amount of time
How should lock-step be avoided
threads should back off for a random amount of time
What should a thread do if i tries and fails to get a lock?
double back-off time, up to a fixed max
how does the lock look of the Backoff lock?
public void lock() {
int delay = MIN_DELAY;
while (true) {
while (state.get()) {}
if (!lock.getAndSet(true))
return;
sleep(random() % delay);
if (delay < MAX_DELAY)
delay = 2 * delay;
}}