Professional Documents
Culture Documents
Is My Spin Lock Implementation Correct and Optimal?
Is My Spin Lock Implementation Correct and Optimal?
Is My Spin Lock Implementation Correct and Optimal?
{
if(lock) loopFor(1 milliseconds);
else
{
lock = true;
return;
}
Also see:
https://preshing.com/20120226/roll-your-own-lightweight-mutex/
Is my spin lock implementation correct and optimal?
Summary:
Deadlock: situation where nobody progress, doing nothing (sleeping, waiting etc..). CPU
usage will be low;
Livelock: situation where nobody progress, but CPU is spent on the lock mechanism and
not on your calculation;
Starvation: situation where one procress never gets the chance to run; by pure bad luck or
by some of its property (low priority, for example);