Yuxiang Group official hotline

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, ban

Only CPU interrupts, means that the operating system does not reschedule a thread, that

Prohibit the thread switch, get the right to use the CPU thread can not be between

Off to execution. So two write operations must be: either have been executed,

Or have not been executed, it is atomic.
However, in multi-core scene, the same time, there may be two threads simultaneously

In execution, a thread executing on the CPU-1, a thread runs

CPU 2-on. At this time, CPU interrupts are disabled, can only guarantee on the CPU

Continuous thread execution, does not guarantee that only one thread execution

Row. If these two threads write to the memory of the long variable high 32

Bit, then it will cause us write variables and we read out

It is inconsistent.

Therefore, an important condition for solving the problem of atomic still is: the same time only

To have a thread to operate on shared variables that are mutually exclusive. If I

We can guarantee that modifications to shared variables are mutually exclusive, then no matter

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/12220205.html