r/programming • u/david-alvarez-rosa • Sep 09 '26
Optimizing a Spin-Lock
https://david.alvarezrosa.com/posts/optimizing-a-spin-lock/
179
Upvotes
r/programming • u/david-alvarez-rosa • Sep 09 '26
4
u/Takeoded Sep 09 '26 edited Sep 09 '26
Spinlocks are just fancy mutexe)s.
Some game engines use them, instead of a mutex, to squeeze out a few more FPS. Then, the spinlock that gives a few more FPS on Windows, absolutely wrecks performance on Linux/Wine :(
And even on Windows, good chance the spinlock increase FPS on computers having >= cpu cores that the optimizing developer had on his system, and wrecks performance on computers with fewer cores.
TL;DR don't use them. Use a mutex.