Memory access and concurrency
For multithread applications, everything hangs on those memory locations. If multiple threads access different memory locations, everything works fine. But if two threads access the same memory location, then you must be very careful. As you have seen in Chapter 3, Language-Level Concurrency and Parallelism in C++, multiple threads trying to read from the same memory location introduce no trouble, but as soon as any thread tries to modify data in a common memory location, chances for race conditions to occur come into the frame.
The problematic race conditions can only be avoided by enforced ordering between the access in multiple threads. As discussed in Chapter 3, Language-Level Concurrency and Parallelism in C++, lock-based memory access using mutexes is a popular option. The other way is to leverage the synchronization properties of atomic operations by enforcing ordering between the access in two threads. In later sections of this chapter, you will see the...