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 font not Copy On Write (COW)) share the following:
- The text segment
- The data segments—initialized data, uninitialized...