Many Execution Paths inside One Process
See exactly what threads share, what each thread must keep independently, how user threads map to kernel schedulable entities, and why shared memory creates both speed and correctness risk.
Reason about concurrent execution
- Describe a thread without calling it a process.
- Separate shared process resources from thread-private state.
- Compare many-to-one, one-to-one and many-to-many.
- Distinguish concurrency from parallelism.
- Trace and explain a lost-update race.
A Thread Is an Execution Unit inside a Process
Threads in one process share the resources that define the process, while each preserves the CPU state needed to execute independently.
private stack
thread ID
private stack
thread ID
private stack
thread ID
Share the process; preserve each execution path
If threads did not keep separate program counters, registers and stacks, one function call or local variable could overwrite another thread’s active execution context.
Why Applications Use Multiple Threads
Responsiveness
A user interface can remain active while another thread waits for storage or network work.
Resource sharing
Threads naturally cooperate through one process address space and open-resource collection.
Economy
Creating and switching threads can require less work than separate processes because more context is shared.
Scalability
Independent work can execute simultaneously on multiple processor cores when the mapping permits it.
Map User Threads to Kernel Scheduling Entities
Select a model to see its mapping, blocking behaviour and parallelism trade-off.
Observe Concurrency and Parallelism on a Timeline
Run the same two threads on one logical CPU or two cores. The work is concurrent in both cases, but simultaneous only with two cores.
Ready to schedule
Advance the timeline to reveal one time slice at a time.
Concurrency Is Overlap; Parallelism Is Simultaneity
Concurrency
Multiple tasks make progress during overlapping periods. On one core, the OS can interleave them by switching between execution contexts.
Parallelism
Multiple tasks execute at the same instant on distinct processing resources. Parallel work is concurrent, but concurrent work need not be parallel.
Make a Lost Update Visible
Two threads execute counter = counter + 1. That source statement contains a read, calculation and write; an unsafe interleaving can lose one update.
Thread A
Thread B
Both increments are pending. Step through the selected schedule.
Common Multithreading Hazards
| Hazard | What goes wrong | Direction of solution |
|---|---|---|
| Race condition | The result depends on an uncontrolled interleaving of shared-data operations. | Protect critical sections or remove shared mutable state. |
| Deadlock | Threads wait forever for resources held in a cycle. | Control acquisition order, timeout or avoid unsafe allocation. |
| Starvation | A thread remains eligible but repeatedly fails to receive required service. | Use fairer scheduling/locking policies or aging. |
| Livelock | Threads keep reacting to each other but make no useful progress. | Break symmetry using backoff or coordination. |
| Thread leak | Threads are created or retained without proper completion and cleanup. | Bound pools, define ownership and join/cancel safely. |
Ten Misconception-Specific Checks
Feedback explains why each selected option fits or fails.
University and Placement Questions
- Define a thread.
- What does a thread share?
- Define concurrency.
- What is a race condition?
- State one benefit of multithreading.
- Compare process and thread.
- Explain multithreading models.
- Differentiate concurrency and parallelism.
- Trace a lost-update race.
- Discuss benefits and costs of threads.
- Can threads run in parallel on one core?
- Why does each thread need a private stack?
- What happens if one user thread blocks in many-to-one?
- Why is a race difficult to reproduce?
- Thread versus asynchronous task?
Show a strong answer: “Process versus thread”
- Define the process as a protected resource container and execution environment.
- Define the thread as an execution path scheduled within that process.
- State shared items: address space, code, heap, globals and process resources.
- State private items: thread ID, program counter, registers and stack.
- Compare creation/switching cost, isolation, communication and failure impact.
- Conclude with when separate processes are preferable: stronger isolation and independent lifetime.
Show a strong answer: “Explain the lost update”
Both threads read the original value before either writes. Each computes the same incremented local value, then both write that value. The second write overwrites rather than adds to the first result, so two logical increments produce only one stored increment. Protect the entire read–modify–write sequence as one critical section or use a suitable atomic operation.
You Can Now Explain Both the Power and Risk of Threads
- Threads share their process’s address space and resources but keep independent execution contexts.
- User-to-kernel mapping determines blocking and parallelism behaviour.
- Concurrency means overlapping progress; parallelism means simultaneous execution.
- A race emerges when a result depends on an uncontrolled ordering of shared-memory operations.
- Correct synchronization protects an invariant without unnecessarily serializing independent work.
Mark Level 4 after you can reproduce the lost update and compare all three main threading models.
Saved only in this browser.