3 ms·
C/C++ language designers used to take the position that concurrency was an OS issue, not a language issue. That came unglued as processors did more and more out
by Animats 11y ago
C/C++ language designers used to take the position that concurrency was an OS issue, not a language issue. That came unglued as processors did more and more out of order operations.
C/C++ language doesn't really understand concurrency. Even locking is iffy, because the language doesn't know what data is locked by a lock. Rust, and to a lesser extent Java, associate locks with data, which gives the compiler some info to guide what it can't optimize. C/C++ have a whole series of kludges - "volatile", "atomic", etc., which patch holes in race conditions but don't provide a coherent concurrency model. Which is why we see papers like this.
- haberman 11y ago> C/C++ have a whole series of kludges - "volatile", "atomic", etc., which patch holes in race conditions but don't provide a coherent concurrency model. Are you aware that C11/C++11 -- the language standards that added atomics -- also defined a coherent memory model?
- caseymarquis 11y agoVolatile is required for working with memory which is subject to change without notice. This is required for signaling that the value may be changed by a physical peice of hardware outside of your control. It's pretty useful.
- pjmlp 11y agoNowadays I look at UNIX (or POSIX) as the actual C runtime. But even that doesn't change much, as the semantics are not consistent across implementations.
- gpderetta 11y ago"C/C++ language designers used to take the position that concurrency was an OS issue, not a language issue" That was the case until Bohem's 'Threads Cannot be Implemented as a Library' position paper, which lead the C++ Standard Committee to formally define the C++ memory model (whose correctness was also independently proven [1]). This standardization work was greatly inspired by the corresponding Java MM, and in a break from the past, it explicitly disallowed a few compiler optimizations and even made the C++ standard unimplementable on a few quirky older architectures for the sake of sanity. Today there are no arguments on whether a concurrent algorithm (and compiler optimizations) is conforming or not, as there are both dynamic and static checkers that can verify it against the C++ memory model. I wish that the same rigorous formalization work were to be done for the strict aliasing rules of the language, which are still a mess of underspecified, ambiguous and mutually contradicting rules scattered all over the standard document. [1] the original drafts had in fact issues which were found when attempting the correctness proof; these flaws have been corrected, except there is a still standing issue with out-of-thin-air values; it is not believed to have any impact on code with current compiler and cpus, but there is an ongoing effort to correct it.
- twic 11y ago> to a lesser extent Java, associate locks with data I'm not sure that's really true. Yes, monitors are attached to specific objects, but the ordering effects of acquisition and release of a lock apply to reads and writes to all objects, not just the one the lock is attached to.