Optimizing a Spin-Lock

(david.alvarezrosa.com)

16 points | by signa11 2 days ago

2 comments

  • tombert 53 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.

  • dalvrosa 2 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