Can testing and tuning be implemented in software without hardware support?

Here Test and Set are written on software:

boolean TestAndSet(boolean *target) { boolean rv = *target; *target = TRUE; return rv; } 

and

 do { while(TestAndSetLock(&lock)) ; // do nothing // critical section lock = FALSE; // remainder section } while(TRUE); 

Is it possible to use a mechanism in a CPU that does not support testing and tuning at the hardware level? If so, how is atomicity ensured?

+6
source share
2 answers

You can use the Lamport "bakery" mutual exclusion algorithm on machines without TAS / CAS to access the "atomic" (protected) value.

http://www.disi.unige.it/person/DelzannoG/SO1/AA0607/bakery.htm

This only gets more complicated if you do not have sufficiently limited N. processes.

0
source

The test and test kit cannot be implemented in software without hardware support, as you suggested.

Precisely because TestAndSet above should be a mechanism that will be used to ensure mutual exclusion, but it is not atomic. Atomicity is just another name for mutual exclusion: the internal variables of TestAndSet must be protected, ensuring that two processes cannot execute its code at the same time.

Thus, you have defined a method for ensuring mutual exclusion, which in itself requires some mechanism to ensure mutual exclusion. This trick can be played several times, but there will be no real progress without any hardware support.

0
source

Source: https://habr.com/ru/post/973311/


All Articles