Basics of the Memory Model
From the concurrency point of view, there are two main aspects of the memory model:
- What is a memory location?
- What happens if two threads access the same memory location?
Let me answer both questions.
What is a memory location?
A memory location is according to cppreference.com
- an object of scalar type (arithmetic type, pointer type, enumeration type, or
std::nullptr_t
), - or the largest contiguous sequence of bit fields of non-zero length.
Here is an example of a memory location:
First, the object obj
consists of seven sub-objects and the two bit fields b
, and c
share the same memory location.
Here are...