Optimizing a Spin-Lock
12 points by signa11 3 days ago | 2 comments

tombert 14 minutes ago
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.

reply
dalvrosa 3 days ago
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

reply