In this case, the changes are visible, because Thread.join
and Thread.start
creates events - before the relationship between actions in both threads. See Memory Negotiation Errors :
When an operator calls Thread.start, every statement that has a happening - before a relationship with that statement will also have a - before a relationship with every statement executed by a new thread. The effect of the code that led to the creation of the new stream is visible to the new stream.
When the thread terminates and calls Thread.join in another return thread, then all the statements executed by the completed thread, a occurs before dealing with all the statements following the successful connection. The effects of the code in the stream are now visible to the stream that performed the connection.
If you did not use these methods in this order, the changes may not be available. Threads should not be started at the same time to cause a problem, because the values may be cached in the stream or some optimization may occur, etc.
source share