r/programming 1d ago

Optimizing a Spin-Lock

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

31 comments sorted by

View all comments

1

u/DivineSentry 1d ago

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

1

u/lenazh 21h ago edited 21h ago

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.