After which the power of the grip and good grip

After which the power of the grip and good grip

Ding
goods
[
Q

Q
. 1
. 3
. 7
. 5


1
0
7
6
]
[] [safe and reliable professional reputation]
Ding
goods
[
Q

Q
1
3
7
5


1
0
7
6
]
[professional] [secure] the credibility of
the single-core CPU scene, that only one thread of execution, CPU interrupts are disabled, means that the operating system does not reschedule the thread, which prohibits the thread switching, access to CPU the right to use threads can be executed 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/fadsa12412412/p/12227506.html