4 ms·
> Java doesn't have the weaker atomics support that C++ added Yes it does, but it doesn't have first-class keywords to represent these modes. You have to use t
by hashmash 3y ago
> Java doesn't have the weaker atomics support that C++ added
Yes it does, but it doesn't have first-class keywords to represent these modes. You have to use the VarHandle class, which is a bit kludgy.
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/invoke/VarHandle.html https://docs.oracle.com/en/java/javase/20/docs/api/java.base...
- jcranmer 3y agoOkay, it looks like those were added in Java 9, which was after I stopped following Java (and well after the C++ memory model was largely settled, in 2007).
- CyberDildonics 3y agoOkay, it seems strange to make a sweeping generalization while assuming java had stagnated.
- re-thc 3y agoBefore Java 9 it could have been done using Unsafe. VarHandle just provides a slightly higher level construct.
- gpderetta 3y agoWas the behavior of more relaxed operations fully formalized in the way it fits with the rest of the memory model?
- hashmash 3y agoNot with the Unsafe class. It was never intended to be used by anything except the built-in concurrency support classes, and it was just barely good enough. External libraries which made use of the Unsafe class did so by studying how it was used, and then assumed/concluded how it worked. Java 9 formalized everything with the VarHandle class, and it offers much more features than the Unsafe class.
- gpderetta 3y agoThanks for the clarification. Java was obviously a trailblazer on formally introducing advanced memory models on practical languages, but it did take a few tries to get it correct.