Figure 3-5.

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

Each thread is represented by a sequence of boxes, one per operation. Within each thread, each box has an arrow to the next. Thread A has four boxes, thread B has five boxes, and thread C has two boxes.

Thread A starts with “load null” followed by “allocate box A”. Thread B also starts with “load null” followed by “allocate box B”.

The next box in thread A is: compare-exchange from null to p, and is labeled with the word “release”. It is followed by “use box A”.

The next box in thread B is: compare-exchange loading p, and is labeled with the word “acquire”. It is followed by “deallocate box B” and “use box A”.

There is an arrow from the compare-exchange operation on thread A to the one on thread B. So, from the release to the acquire operation.

There is also an arrow to from the compare-exchange operation on thread A to the first operation of thread C. That operation is “load p”, and is labeled with the word “acquire”. There is no compare-exchange operation on thread C. The load operation is followed by “use box A”.

So, the final box of all three threads reads the same: use box A.