3 ms·
Close, but not fully. Volatile enforces using an assembly read instruction (does not use a register cached value), but no memory barriers. In ye (really) olden
by jeffreygoesto 4y ago
Close, but not fully. Volatile enforces using an assembly read instruction (does not use a register cached value), but no memory barriers. In ye (really) olden days that seemed enough, but then you know, backwards compatibility...
- dragontamer 4y agoWell, that's what Java's "volatile" actually enforces. C's "volatile" isn't enough, but more recent C compilers have atomics and memory models. The memory-model problem wasn't solved until the 00s (that late!!!) when multicore CPUs became more commonplace. Java, C++11, and other language / language updates after that point quickly adopted memory models. And the rest is history. So yeah, use atomics + memory barriers.