1

I understand that algorithms for mutual exclusion such as Dekker's algorithm and Peterson's algorithm require an underlying sequentially consistent memory model to work (or use of memory barriers), but it's not clear to me if they require atomic loads and stores. In the wikipedia entry for Peterson's algorithm it says this:

The algorithm satisfies the three essential criteria to solve the critical section problem, provided that changes to the variables turn, flag[0], and flag1 propagate immediately and atomically.

I'm not clear on the quoted bit above and whether or not that means the algorithm requires atomic loads and stores to work. Looking at Peterson's algorithm I don't see why atomic loads and stores are required for it to work. I don't see mention of this atomicity requirement in the Dekker's algorithm wikipedia entry. So does Peterson's algorithm require atomic loads and stores and does this extend to all mutual exclusion algorithms?

Mike Sweeney
  • 1,896
  • 2
  • 18
  • 20

1 Answers1

1

Yes, it does require them to be atomic. Dekker's algorithm does too.

Suppose turn and flag are not atomic. That means that P0 can set turn and flag[0], but there exists an interval of time when P1 can still view them as not set, and can enter its critical section. Symmetrically, P0 can enter the CS too.

Sriram Srinivasan
  • 1,255
  • 17
  • 16
  • Moreover: any lock whatsoever on a non-sequentially-consistent platform (basically, any modern platform) requires atomics to be used somewhere. – Zazaeil Feb 27 '23 at 18:45