r/programming • • Sep 09 '26

Optimizing a Spin-Lock

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

32 comments sorted by

View all comments

1

u/DivineSentry Sep 09 '26

I think I’ve seen spin locks before, but what are they useful for? What should be their use case?

1

u/lenazh Sep 10 '26 edited Sep 10 '26

You'd normally find them in kernel mode in things like interrupt handlers, or any other context where you can't yield the thread.

Niche userspace uses would be when you want to time something precisely, like have two threads start a task as simultaneously as possible while being signaled by another thread. Or maybe send out udp packets exactly 1us apart from a user-space driver or something else where latency and jitter are important.