long and double assignments are not atomic - How does it matter?

前端 未结 3 1637
-上瘾入骨i
-上瘾入骨i 2021-02-10 17:07

We know that long and double assignments are not atomic in Java until they are declared volatile. My question is how does it really matter in our programming practice. for inst

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 17:40

    Where improper programming with an int may result in stale values being observed, improper programming with a long may result in values that never actually existed being observed.

    This could theoretically matter for a system that only needs to be eventually-correct and not point-in-time correct, so skipped synchronization for performance. Although skipping a volatile field declaration in the interest of performance seems on casual inspection like foolishness.

提交回复
热议问题