3 ms·
This 2020 review carefully summarizes the overly complex and error-prone outcome of programming language memory model changes in the early 2010's. It's temptin
by w10-1 2y ago
This 2020 review carefully summarizes the overly complex and error-prone outcome of programming language memory model changes in the early 2010's. It's tempting to master such tricky details, but doing so almost inevitably leads to the costliest bugs ever: rare data corruption that's impossible to detect and reproduce.
Russ Cox in 2021 offered a higher-level insightful history of evolving hardware and software support for concurrency, discussed just yesterday
https://news.ycombinator.com/item?id=42397737
His take (as I take it): systems programmers should only use sequentially-consistent atomics (and only via well-tested concurrent data structures).
Easy peasy! ;p
- tialaramex 2y agoI am inclined to agree with the opinion that Sequentially Consistent Atomics are another of the long list of wrong defaults chosen by WG21 (the C++ committee). The argument goes roughly like this: If you don't offer a default here, the programmer who supposes that the answer to their question is atomics will be obliged next to figure out which Order they wanted. Or they could give up and say "I need a grown-up". Because C++ chooses to offer Sequentially Consistent as the default that programmer will presume this must mean it now does what they naively anticipated. Russ' overview might suggest that's true too. Here's the problem: It may not do what they wanted, it may be that no ordering rule would achieve their actual goals, but since they weren't asked to go read the ordering rules and pick one, they never confronted this awful problem, and are instead blissfully unaware. They are strolling into traffic knowing that they've picked the best possible road crossing rule and not aware that in fact no possible rule could make crossing this Interstate on foot safe to do. Here's another bad problem: If it does achieve what they wanted, it's probably overkill. The only reason programmers should reach for atomics is that the provided facilities which were safe for them to use didn't deliver the performance they need. But the Sequentially Consistent ordering may hurt their performance, injecting barriers they don't need, using slower instructions or even stalling when that was unnecessary. If they'd read the rules they might for example have realised they only needed a Relaxed ordering - much better, or that with a slight tweak they can use Acquire/Release.