3 ms·
> Personally I had never fully grokked the reordering based memory barriers (I understood what they did, but it was hard for me to understand all the implicatio
by dragontamer 7y ago
> Personally I had never fully grokked the reordering based memory barriers (I understood what they did, but it was hard for me to understand all the implications); on the other hand the C++11 memory model and its happens-before based somehow seems much more natural and it helps me retrospectively to understand even barrier based code.
Same here. C++11 memory model is when I managed to "wake up" to the facts behind barriers, load/load and store/store dependencies, and all that good stuff.
I recognize that Java apparently specified all of this stuff first, but I wasn't a Java programmer at that time. So I learned it from C++11 (Or more specifically: Herb Sutter's talks + other C++11 programmers)
---------
EDIT: For anybody who has issues with memory barriers, think about a spinlock and where the appropriate memory barriers need to go for a spinlock to work. That's the real beauty of C++11/Java model: instead of thinking in terms of load/load or load/store or store/store barriers, you think in terms of "lock acquire" and "unlock release".
The spinlock is the canonical example of memory barriers, and "remembering" that through the use of language is helpful.
- kjeetgill 7y agoAny links you have to these talks would be invaluable, thanks!
- dragontamer 7y ago* https://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-1-of-2 https://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-20... * https://www.youtube.com/watch?v=lVBvHbJsg5Y https://www.youtube.com/watch?v=lVBvHbJsg5Y EDIT: Honorable mention is Preshing's blog. https://preshing.com/20131125/acquire-and-release-fences-dont-work-the-way-youd-expect/ https://preshing.com/20131125/acquire-and-release-fences-don... There's so much there its hard to pick out anything in particular in Preshing's blog as a "must read". Its all very useful, but its also spread out over a lot of posts. I just picked the first link from search engines EDIT2: Honorable mention#2: The OpenCL 2.0 standard section 3.3.6: https://www.khronos.org/registry/OpenCL/specs/opencl-2.0.pdf https://www.khronos.org/registry/OpenCL/specs/opencl-2.0.pdf The C++11 draft standard defines "happens before" and all that good stuff, but it is a 1000+ page document. OpenCL 2.0 copy/pastes from the C11 / C++11 standards and puts it all in one section: 3.3.6, which is only about 3ish pages long (+additional pages for OpenCL specific stuff). OpenCL2.0 is missing consume/release semantics, but nobody implemented that yet anyway (even in C++ world, no one has bothered to properly implement a consume/release compiler yet). I guess OpenCL2.0 has the whole "local vs global" memory order thing going on, while C11 / C++11 is all one memory space. But I personally found OpenCL2.0's specification to be easier to read than the C++11 draft standard.