Trying to understand atomicity from the new valhalla-spec-observers post

Quân Anh Mai anhmdq at gmail.com
Mon Apr 10 09:28:49 UTC 2023


Hi,

Atomicity is the behaviours of memory reads/writes under race conditions.
If there is no race condition (the variable is not accessed from multiple
threads or protected properly by locks) then the observed value is always
the latest written one. As a result, if you serialise your accesses
properly, there is no need to worry about atomicity. And in general, it
should be rare that you want to access variables without proper
synchronisations, and you should not do so.

As this is rather uncommon and requires you doing clever things for it to
make differences. Other languages often do not worry giving up this
property. C and C++ straight invalidate your entire program, Go and C# give
you unspecified result when accessing variables larger than machine word.

In conclusion, you will most likely not observe the non-atomicity of any
variable, except when you are trying to do clever things (accessing
variables racily) and in those cases, you need to carefully study the Java
memory model.

To quote from the Go memory model: Don't be clever.

Best regards,
Quan Anh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20230410/a7f3d700/attachment.htm>


More information about the valhalla-dev mailing list