2 ms·
Eh, the portability is actually getting a lot better nowadays. Most consumer and server processors being released in the last few years support double-world com
by alfalfasprout 10y ago
Eh, the portability is actually getting a lot better nowadays. Most consumer and server processors being released in the last few years support double-world compare and swap. Atomic increment, load, store, etc. are also pretty widespread now.
The key is like someone said above that you cannot make your code ambiguous. In C++ especially, the atomic primitives can compile to different instructions depending on how you use them so it's important to be very explicit.
One thing that can be a pain is memory fences. The guarantees can be different on different CPUs so you can run into weird bugs. In my case, generally I compile to target particular CPUs on servers we own so it's not a big deal. But I can imagine for consumer software this can be a huge pain.
- mikeash 10y agoI haven't seen too much recent stuff. I made this fix probably around 2004, and the code was at least a couple of years old at that point. We initially targeted PPC Mac, then it eventually expanded to x86 Mac and ARM iOS. All fairly similar when it comes to simple stuff like this, the barriers are straightforward when needed, and no need for DCAS or similar fanciness. (Indeed, no need for any CAS at all.)