r/programming • • Sep 09 '26

Optimizing a Spin-Lock

https://david.alvarezrosa.com/posts/optimizing-a-spin-lock/
183 Upvotes

32 comments sorted by

View all comments

Show parent comment

17

u/monocasa Sep 09 '26

I'd argue that they're a less fancy mutex, since they're basically like mutexes that don't bother informing the scheduler in the contended case.

1

u/Takeoded Sep 11 '26

They also eat all the CPU they can get, until it unlocks :( eating 100% of 1 core until the lock clears

1

u/monocasa Sep 12 '26

Not necessarily.

On a SMT system, it's common to use instructions like monitor and pause to stop the one hardware thread and give priority to the others.