Unit content
Threads within a process
A thread is one execution context within a process. Threads in the same process share the process's address space and many operating-system resources while keeping their own execution state.
Each thread has its own program counter, registers and call stack. Heap objects and global memory are normally visible to all threads in the process.
process address space
├─ shared code and data
├─ thread A: registers + stack
└─ thread B: registers + stack
Why threads help on one core
A thread can block waiting for input, a timer or another event while another runnable thread continues. Concurrency can therefore improve structure and responsiveness even when only one core executes instructions at a time.
Shared memory changes correctness
Because threads can access the same mutable objects directly, communication can be cheap but unsafe interleavings become possible. Synchronization is required when correctness depends on coordinating those accesses.
Threads trade some of the isolation of separate processes for cheaper shared state and multiple execution contexts within one application.