Yuxiang International Chess agency

Yuxiang International Chess agency

Ten
[
electric _
K

. 1
. 9
. 9

. 8
. 8
. 3
. 6

. 9
. 9
. 9
. 9
]
[
Q;
K
_
. 6
. 9
. 5

. 8
. 9
. 9

. 9
. 9
]
[professional reputation] [safe]
single-core CPU scenes , that only one thread of execution, CPU interrupts are disabled, meaning Caozuoxitong will not reschedule the thread, which prohibits a thread switch, obtain the right to use the CPU thread can execute without interruption. So two write operations must be: either were executed or have not been implemented, atomic.
However, in the multi-core scenarios, the same time, there may be two threads simultaneously executed, a thread executing on the CPU-1, a thread executing on the CPU-2. At this time, CPU interrupts are disabled, can only guarantee continuous thread on the CPU to perform, does not guarantee that only one thread of execution. If these two threads write to the high long-type variable 32 to the memory, then it will cause the variables we write and we read out is inconsistent.

Therefore, an important condition for solving the problem of atomic still is: the same time, only one thread to operate on shared variables that are mutually exclusive. If we can guarantee that modifications to shared variables are mutually exclusive, then, whether it is a single core CPU or multi-core CPU, it can guarantee atomicity.

The following will introduce the program to achieve mutually exclusive access, locking mechanism.

Guess you like

Origin www.cnblogs.com/fadsa124656542/p/12220425.html