16 points signa11 2 days ago 8 comments

dalvrosa 2 days ago | parent

Thanks for sharing! Happy to get feedback :)

Note that I don't recommend spinlock for most cases, only when there is a 1:1 mapping between threads and phsycal CPU cores, and only after measuring

tombert 1 hour ago | parent

I genuinely had not heard of anyone actually using a spinlock in production code until I started using LMAX Disruptor a few years ago.

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".

I still haven't actually explicitly written a spinlock for anything in production, but Disruptor has shown me that there are cases for it.

sedatk 47 minutes ago | parent

It’s one of the secret ingredients to avoid a Big Kernel Lock™.

BoingBoomTschak 46 minutes ago | parent

ignoramous 27 minutes ago | parent

> had not heard of anyone actually using a spinlock in production code

Go stdlib sync.Mutex uses spins: https://victoriametrics.com/blog/go-sync-mutex / https://archive.vn/BIb7F

mathisfun123 26 minutes ago | parent

not all architectures have atomic cas

bob1029 21 minutes ago | parent

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.

jeffbee 6 minutes ago | parent

This would have different answers depending on if it ran on a machine with a more closely-shared cache, right? For example on an Intel efficiency core cluster where 4 cores share an L2.