3 ms·
My possibly-incorrect understanding is that in C++ terms, every field in Java is a relaxed atomic. In both languages this gives you very confusingly defined but
by plorkyeran 3y ago
My possibly-incorrect understanding is that in C++ terms, every field in Java is a relaxed atomic. In both languages this gives you very confusingly defined but not undefined behavior.
A non-performance argument against Java's decision is that relaxed atomics have turned out to have much more complicated semantics than was expected in the 90s and 00s, to the extent that most code using them is probably incorrect. Java telling developers that data races are okay leads to people writing buggy code, and because it's legal you can't have something like TSan in Java to trap on data races.
On the performance side, this decision inhibits some optimizations and while relaxed 32-bit atomics are free on all non-exotic hardware, that isn't the case for 64-bit atomics.
- raphlinus 3y agoIt's essentially the same as a relaxed atomic at the machine level, but it's weaker - it corresponds to "unordered" in the LLVM sense. In particular, it allows for a lot more optimization - operations can be reordered with respect to each other as long as the compiler is aware that they refer to disjoint memory locations.