Java memory model and concurrency
1. Concurrency:
A) concurrency must involve a number of execution flows
b) There must be a sharing of data between multiple execution streams (if all private data is not affected by each other (because the hardware has the concurrency transparency of the hardware resources first, and then no shared data, which is equivalent to the individual execution flows running alone in a separate closed context))
C
I. What are the links between parallel execution flows, or how are they coupled? In addition to being able to expropriate shared resources on the hardware (which is guaranteed to be unaffected by the underlying hardware), it is a competitive relationship that shares the same data and waits for other counties or notifies other threads of the partnership. Moreover, the cooperative relationship is passed on the underlying hardware through the sharing of certain States to implement the message. The realization of competitive relationship is also realized by sharing state. In essence, competition and partnership are a form of communication between multiple execution streams, or a manifestation of synchronization. Multiple execution streams share state synchronization is the underlying, and the implementation of collaboration and the exclusive sharing of data on the upper level of the shared state of an application.
Ii. shared state such a communication or synchronization must be the test-set of the atom of the hardware or the support of this kind of atomic instruction or the global shackle of the global blockade bus can achieve
Iii. in further abstraction, shared state communication is only one way to communicate with multiple execution flows. How can the shared state of communication or synchronization be used on a single machine or on a single unit of shared main memory, but how does the execution flow between multiple machines get synchronized? Because there is no data sharing between the multiple execution flows, it is first to transmit the state of the pre-agreed encoding by means of communication (specifically, the communication that transmits the information), and multiple execution flows start in a specific state, and then obtain a wide range based on the passed encoding and the protocol of the multi-process synchronization that is well designed. Synchronization of multiple execution streams on different machines.
Iv. as a result, multiple execution streams can be synchronized (state sharing or Communication + protocol + encoding state), whether on a single machine or on a different machine. Synchronization here refers to the consensus that the system is in a sub-state. Based on the synchronization that has been achieved, it is possible to achieve collaboration and competition between execution flows.
D) Therefore, synchronization is a kind of consensus in the state of the system. Multiple execution streams based on synchronization enable collaboration and competition. The implementation of synchronization is different on the same machine and on different machines. State sharing on the same machine can be thought of as a degenerate form of implementation on multiple machines.
e) Collaboration is a synchronization that is a common understanding of whether a state is true or false, or whether a particular data is a specific value, and the exclusive sharing of data. To prevent errors, the initiator needs to provide the underlying read and judge and set atomic operations, and the recipient needs to provide the underlying judgment and jump to such atomic operations or similar means of implementing the same intent (total thread, interprocess synchronization).
f) How does Java implement synchronization of multiple execution streams? In terms of scope, this synchronization is in-process synchronization as discussed above. java specifies that the storage model used between multiple threads is a private cache plus shared main memory. and Java prescribes a first-in-one relationship Happens-before order (including several, which have shackles and unlocked relationships, thread-initiated relationships, statement-successively relationships). If some of the statements in the program are implemented in a specific order, then the ordering of the related operations must be done through a predefined happends-before operation, such as by adding locks. Locking is the atomic synchronization mentioned in E above. Other applications for Java in-process synchronization also include exclusive shared data and collaboration (Happens-before Order in Java contains collaboration semantics)
The nature of synchronization Java memory model happen before order