Is this a real spinlock?
Closed this issue · 1 comments
straightdave commented
Should the Goroutine keeps doing something before trying to get lock periodically when it fails to get the lock, rather than giving up the processor time by calling `runtime.Gosched()?
OneOfOne commented
That haven't been updated in a long time, however when I wrote it, without the Gosched
, the whole program would freeze.
Also most (all?) spinlock implementation does something similar.
from https://locklessinc.com/articles/locks/:
static void spin_lock(spinlock *lock)
{
while (1)
{
if (!xchg_32(lock, EBUSY)) return;
while (*lock) cpu_relax(); <<<<<
}
}