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.
source share