Value integrity guarantee for concurrent long writes in 64-bit OpenJDK 7/8

前端 未结 2 1470
广开言路
广开言路 2021-02-08 11:32

Note: this question isn\'t related to volatile, AtomicLong, or any perceived deficiency in the described use case.

The property I am trying to prove or rule out is as f

2条回答
  •  梦谈多话
    2021-02-08 12:13

    https://www.securecoding.cert.org/confluence/display/java/VNA05-J.+Ensure+atomicity+when+reading+and+writing+64-bit+values

    VNA05-J. Ensure atomicity when reading and writing 64-bit values

    ....

    VNA05-EX1: This rule can be ignored for platforms that guarantee that 64-bit long and double values are read and written as atomic operations. Note, however, that such guarantees are not portable across different platforms.

    The link above discusses this issue in the context of security and seems to suggest that on 64 bit platforms you can indeed assume long assignments to be atomic. 32 bit systems are becoming somewhat rare in server environments, so it is not a strange assumption to make. Do note that the exception is a bit vague on which platforms make this guarantee and doesn't explicitly state that 64 bit openjdk on 64 bit intel is fine for example.

提交回复
热议问题