While reading Java docs on Memory Consistency errors. I find points related to two actions that creates happen - before relationship:
When a statement invokes
Thread.start()
, every statement that has a happens-before relationship with that statement also has a happens-before relationship with every statement executed by the new thread. The effects of the code that led up to the creation of the new thread are visible to the new thread.When a thread terminates and causes a
Thread.join()
in another thread to return, then all the statements executed by the terminated
thread have a happens-before relationship with all the statements
following the successful join. The effects of the code in the thread are now visible to the thread that performed the join.
I am not able to understand their meaning. It would be great if someone explain it with a simple example.