Queueing Lock Implementation

init:
	flags[0] = has-lock;
	flags[1..p-1] = must-wait;
	queuelast = 0; // global variable

lock:
	myplace = r&inc(queuelast); // get ticket
	// spin
	while(flags[myplace mod p] == must-wait)
	// now in C.S
	flags[myplace mod p] = must-wait;

unlock:
	flags[myplace+1 mod p] = has-lock;

Under high loads
– queue best(most scalable), test_and_test_and_set worst
– static better than dynamic, ref, better than release(avoid extra invalidations)