Will there be conflicts if two people operate a register at the same time?

Such as the title: Will two people operate a register at the same time conflict?

First of all, the conclusion: No, so there is no need to add locks.
Some people may not be able to figure out why.
Theoretically, from a hardware point of view, there will be conflicts between reading and writing (assuming that both reading and writing are on the rising edge, and the register has circuits on both sides, one side is read and one side is written), but when designing registers, the designer must Considering this problem, a logic circuit with reciprocal reading and writing is added. It cannot be written when reading, and vice versa, so there is no conflict when the user operates. In addition, the register bus can only be controlled by one register at the same time. to transmit data.
So why do we consider the mutual exclusion of an integer in user space? This is because this number is loaded into the cache for execution when two threads process it, and the numbers seen by the two threads are not handled by the other party. after the number.
You can see it here: Memory design (NAND gates start to design memory )

So to see if it is necessary to add a lock, it depends on whether this section of memory space has been cached. If there is a cache, then it must be added. If there is no cache, and the register is directly operated, then there is no need to add it.

Guess you like

Origin blog.csdn.net/weixin_43360707/article/details/129445888