For a given atomic variable, there exists a “modification order” for it. After thread 1 test_and_sets is a value from 0 to 1, it is not possible for thread 2 to see 0.
The memory order affects how all other memory addresses are synchronized. If one thread changes an atomic variable with memory order_release, then any thread that reads the same variable with memory_as_akir "sees" each memory, changes the first thread made before its release.
Acquisition and release is not related to the atom. This means that each thread that successfully blocks the spin lock "sees" changes in each thread that has previously blocked it.
Modification order is the key to blocking the algorithm. Both threads 1 and 2 try to make test_and_set on the same variable, therefore, according to the rules, one modification "occurs before" the other. Since test_and_set, which "occurs before", the other goes into "progress", at least one thread should always make progress. This is the definition of lockfree
source share