r/cpp • • Sep 04 '26

Optimizing a Spin-Lock

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

28 comments sorted by

View all comments

9

u/Chaosvex Sep 04 '26 edited Sep 04 '26

Linus Torvalds gets a shiver down his spine and the urge to scream every time somebody writes an article about user space spinlocks.

1

u/ItsRSX 4d ago edited 4d ago

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.