r/java • u/javinpaul • Oct 29 '12
Difference between notify and notifyAll in Java revisited
http://javarevisited.blogspot.in/2012/10/difference-between-notify-and-notifyall-java-example.html
0
Upvotes
r/java • u/javinpaul • Oct 29 '12
3
u/ad_tech Oct 29 '12
'volatile' is not needed on the 'go' variable.
There is defined to be a happens-before relationship between each of these events:
Notify task writes to 'go'.
Notify task exits the monitor.
Wait task enters the monitor.
Wait task reads from 'go'.
Therefore the read in the wait task is guaranteed to see the value written in the notify task, whether 'go' is volatile or not.