Benefits
| Benefit | Why it happens |
|---|---|
| Increased efficiency | CPU can work on another task while one is waiting (e.g. I/O) |
| Better resource use | Time-slicing reduces idle processor time |
| Improved responsiveness | Foreground UI can stay active while background work continues |
Drawbacks
| Drawback | Why it is a problem |
|---|---|
| Potential delays | More active tasks means each gets CPU time less often |
| Context-switch overhead | Saving/loading task state reduces useful work time |
| Higher complexity | Concurrency bugs are harder to reason about and test |
| Limited suitability | Dependency-heavy tasks still require sequential order |
Scenario: steps depend on each previous result.
result = step1()
result = step2(result) // depends on step1
result = step3(result) // depends on step2
When to choose sequential over concurrent:
| Situation | Better approach |
|---|---|
| Strong step dependencies | Sequential |
| Very small tasks | Often sequential (avoid overhead) |
| Heavy synchronisation needs | Often sequential/simpler design |
| High shared-resource contention | Sequential or carefully controlled concurrency |
Shared Data: Race Conditions, Record Locking and Deadlock
| Term | Meaning | Example in an online ticket system |
|---|---|---|
| Race condition | Two processes read and change the same data at overlapping times, so the result depends on which finishes first and one update can be lost | Two customers are both shown the last seat as free and both buy it |
| Record locking | Only one process at a time is allowed to change a record; the others must wait until it is released | The seat record is locked while the first customer pays |
| Deadlock | Two processes each hold a resource that the other needs, so neither can ever continue | One process has locked the seat record and is waiting for the payment record, while another has locked the payment record and is waiting for the seat |
• Many users or tasks are served at once, so response time and throughput improve
• Shared data must be protected with locks, and waiting for a lock slows the other processes down
• The program is harder to write, test and debug, because faults such as race conditions depend on timing and may not appear in every test run
• The time saved is limited by the parts that must still run in sequence and by the number of processors available
Key Terms Summary
| Term | Definition |
|---|---|
| Concurrent processing | Tasks share CPU time slices to appear simultaneous on one processor/core |
| Parallel processing | Multiple processors/cores execute tasks at the same time |
| Processor time slice | Small CPU time segment allocated to one task |
| Context switching | Saving one task's state and restoring another's during task switch |
• Understand the difference between concurrent and parallel processing
• Be able to identify when concurrent thinking applies
• Explain benefits (efficiency, resource use) and drawbacks (overhead, delays)
• Recognise when sequential processing is better
• Understand time-slicing and context switching concepts
• Give real-world examples of concurrent vs parallel processing