r/cpp • • Sep 04 '26

Optimizing a Spin-Lock

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

31 comments sorted by

View all comments

Show parent comment

1

u/ItsRSX Oct 05 '26 edited Oct 05 '26

With trash code like this, I cant imagine why. I like how the OP cites something about Intel from the mid 10s whose article probably also mentioned to check RDTSC, because __mm_pause is now very much subject arbitrary power down, aggressive SMT surrendering conditions, and vendor specific quirks. Not only that, that timeout back off is way too long for a mere fast-path of an otherwise yielding primitive. "Something something its a spinlock so it doesnt matter...?" Then for no reason whatsoever OS vendors hate it when you roll spinlocks by yourself.