The racing problem
First and foremost, let's attempt to understand what and where exactly the problem we are trying to resolve is. In the previous chapter, we learned that all threads of a process share everything except for the stack; each thread has its own private stack memory space.
Look carefully again at Chapter 14, Multithreading with Pthreads Part I-Essentials: Fig 2, (leaving out the kernel stuff); the virtual address space—the text and data segments, but not the stack segment—are shared between all threads of a process. The data segment, of course, is where global and static variables reside.
At the risk of overstating these facts, this implies that all the threads of a given process truly (if not poss, then make COW also normal ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access