I’m solving a problem of iterative calculation of some lower bound of the answer in a multi-threading environment.
During the calculation, it could happen that number of threads would try to update a common primitive variable. It doesn’t matters for me which one of them would succeed to write it’s value and which would fail.
The only problem I’m bothered about is if it possible that one of the threads would write part of the primitive (e.g. first bytes) and another would write another part (e.g. last bytes) and as a result the value of that primitive would be non of what the threads were trying to write.
A link to an official literature would be very appreciated.
Thanks in advance.
Citing the Java Language Specification:
Writing to other primitives is always atomic. However, if they are not declared
volatilethen updates may not be visible to other threads for an arbitrarily long time.