Revisiting shared resources through the C++ memory model via spinlock implementation
We learned about atomic operations back in Chapter 7. In this chapter, you learned that the placement of atomic variables in the cache is crucial as well. Originally, atomics and locks were introduced because of correctness when multiple threads want to enter the same critical section. Now, our investigation will continue a bit deeper. There’s one last piece of the puzzle of atomic operations. Examine the following snippet:
Thread 1: shrd_res++; T1: load value                       T1: add 1 Thread 2: shrd_res++; T2: load value                       T2: add 1                    ...