I genuinely had not heard of anyone actually using a spinlock in production code until I started using LMAX Disruptor a few years ago.<p>I was always told that they were an anti-pattern, and I think that generally that is a pretty good rule of thumb, but I guess like most stuff in CS: there are always exceptions to "good rules of thumb".<p>I still haven't actually explicitly written a spinlock for anything in production, but Disruptor has shown me that there are cases for it.
To be really pedantic, it's a spin wait, not a spin lock in disruptor. You are waiting for a sequence, not mutually excluding some resource. Many threads can watch the same volatile at the same time without blocking each other.
I think Linus says it well: <a href="https://www.realworldtech.com/forum/?threadid=189711&curpostid=189723" rel="nofollow">https://www.realworldtech.com/forum/?threadid=189711&curpost...</a>
It’s one of the secret ingredients to avoid a Big Kernel Lock™.
> <i>had not heard of anyone actually using a spinlock in production code</i><p>Go stdlib <i>sync.Mutex</i> uses spins: <a href="https://victoriametrics.com/blog/go-sync-mutex" rel="nofollow">https://victoriametrics.com/blog/go-sync-mutex</a> / <a href="https://archive.vn/BIb7F" rel="nofollow">https://archive.vn/BIb7F</a>
not all architectures have atomic cas