Figure 4-1.

A diagram showing happens-before relationships in a situation with two threads.

Each thread is represented by a sequence of boxes, one per operation. Within each thread, each box has an arrow to the next.

The first thread has three operations:

  1. lock: acquire-swap locked from false to true,
  2. access protected data,
  3. unlock: release-store false in locked.

The second thread starts with a repeating operation: acquire-swap locked from true to true. That sequence ends with: acquire-swap locked from false to true. All these swap operations together form a group labeled “lock”.

Only the last swap operation has an incoming arrow from the unlock operation on the first thread. The word “false” is emphasized, to show that the arrow was created because of the acquire operation observing the “false” that the release operation stored.

The second thread continues with “access protected data”, and finally “unlock: release-store false in locked”.