Home > OS >  What is the difference between process mutex in TSL and Swap?
What is the difference between process mutex in TSL and Swap?

Time:09-17

Almost two instructions as if running, advantages and disadvantages are also similar, then what's the difference?

CodePudding user response:

The two instructions do similar, atomic operation, busy waiting, are all need hardware support, on the implementation, swap requires two parameters, do not need to return, and test_and_set is need to use a Shared variables to achieve mutually exclusive, specific implementation details do not need to consider, but the design of the general direction is consistent,
In addition, on a multiprocessor computer, TSL instruction is relatively common, he can realize mutual exclusion, multiprocessor TSL instructions executed the CPU will lock the memory bus, and in the instruction cycle, precisely, should be before the end of the instruction execution, don't allow other CPU access memory,
For swap command, you can think about it, the nature of this instruction is a key to open a lock, that if there are multiple locks? Lock to lock up more variables of the same or different?
Two instructions are doing is the same, but as a result of the design of instruction, lead to what they can do is different,
As in mathematics: the intersection of A and B are not empty, but also is not equal to B
  • Related