Remix.run Logo
▲ aw1621107 5 hours ago

> You can do it all with library functions that just take regular int* (and so on).

It's not just about atomics, but you might still find Hans Boehm's 2005 paper "Threads Cannot Be Implemented As a Library" [0] interesting. It describes (among other things) correctness and performance issues that can arise if the compiler and/or language don't know about thread/atomic semantics.

[0]: https://web.stanford.edu/class/archive/cs/cs240/cs240.1236/o...

▲Joker_vD 3 hours ago | parent [-]

Yeah, it's all fun and games until you realize that you compiler may invent writes in order to eliminate a branch. Which is rather nonsensical, when you stop to think about it — surely an additional store to global can't be faster than a mispredicted branch?

▲homosapien97 2 hours ago | parent | next [-]

Branch mispredictions on deep machines can be devastating, whereas a store can hit in your L1. Storing can definitely be faster than a mispredicted branch if you think you'll hit in your L1/L2

▲adgjlsfhk1 2 hours ago | parent | prev [-]

store to a global is typically 0 cycles (although subsequent reads may be slowed down)