Garbage collection and synchronized visibility

前端 未结 1 1850
隐瞒了意图╮
隐瞒了意图╮ 2021-01-16 05:13

I have read about marking an object as volatile doesn\'t guarantee visibility of it\'s members ( I\'m not saying about thread safety just memory visibility

相关标签:
1条回答
  • 2021-01-16 05:31
    1. Yes, happens-before relationship will gurantees that. While volatile keyword also builds happens-before relationship between the write thread and the read thread.

    Using volatile variables reduces the risk of memory consistency errors, because any write to a volatile variable establishes a happens-before relationship with subsequent reads of that same variable.

    1. The java language specification does not mention it, or any specific mechanism about how to implement volatile. So I guess it depends on the specific JVM.
    0 讨论(0)
提交回复
热议问题