===java the role of the memory model. The Java memory model defines the abstract relationship between threads and threads and the main memory. Each thread has its own area of memory, which is a copy of the variable copied from the main memory, which is an abstract concept. The communication between threads is flushed through main memory, and the modified data is refreshed to the main memory, which is available to other threads. = = = Considering that the memory model cannot escape the command reordering in order to improve performance, the compiler and the processor will do the command reordering. Command reordering follows a set of rules in single-CPU and single-threaded conditions: 1. If you have data dependencies such as write-and-read first, read and write again, do not reorder; When you control dependencies, you cache the results of the calculations and then wait for the criteria to be judged. A = 1;b = 1;bool = True;c = a + b; if (bool) {c = a * A;} 2. Ensure that the results are not changed in the case of reordering. command reordering in the case of multithreading, memory visibility issues may occur if you do not synchronize. Happens Beforejava provides programmers with an easy-to-manipulate reordering rule, which is happens before rules. He is a rule that represents visibility, such as a happens before B, which indicates that a's execution result is visible to B, but does not require a to be executed before B. Each happens before rule corresponds to a series of reordering rules at the bottom, and we don't need to know how the underlying is reordered, equivalent to providing us with a set of rules that make it easier to understand the order reordering.
Java Foundation---Multithreaded---java memory model