Processes and Threads Through One Shared-State Example
Threads in one process commonly share its address space while keeping their own execution context. Separate processes often exchange data through explicit interfaces.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace two workers
Two threads updating one in-process list can observe the same object. Starting two ordinary processes holding separate lists produces different local state unless they intentionally share it. Object identity supplies the relevant question about the list.
Check the communication mechanism
A pipe sends bytes between endpoints. Shared memory requires coordination to preserve each data structure's state. See threads and address spaces for the system model.[1]
Compare two writers to the same logical counter
Threads in one ordinary process can share a counter in memory. If both read zero and then each writes one, an increment can be lost without synchronization. Separate processes can keep independent counters unless they use deliberate shared memory or another common store. See choosing a process or thread.
Shared counter: both read 0, both store 1 → final 1
Independent counters: each starts 0 and becomes 1
Combined count needs a synchronization or communication contract
State which isolation you are relying on
Threads still have separate stacks and execution histories. Processes can share resources such as files. Test the actual communication design, including boundary failures and ownership of shared data.