2.1.5 Thinking Concurrently
2.1.5(a) Concurrent Thinking
Understanding Concurrent Thinking
Scenario: for each passing car, record number plate and colour.
| Approach | What happens | Typical outcome |
|---|---|---|
| Sequential | Record all plates first, then try colours later | Missing/mismatched data likely |
| Concurrent thinking | Capture plate + colour together per car event | More complete and accurate records |
• Better data consistency (plate matches colour)
• More efficient handling of each event
• Less risk of missing information
| Concept | Meaning | Example |
|---|---|---|
| Concurrent processing | One core rapidly time-slices between tasks | Browser + music + update on single-core CPU |
| Multicore processing | Different cores handle tasks simultaneously | One app per core on multi-core CPU |
| Everyday concurrency pattern | Multiple active activities with shared resources/time | Cooking multiple dishes, supermarket checkout lanes |
2.1.5(b) Concurrent Processing
Concurrent vs Parallel Processing
| Feature | Concurrent processing | Parallel processing |
|---|---|---|
| Hardware basis | Usually single core/processor time-sharing | Multiple cores/processors |
| Execution style | Rapid switching between tasks | True same-time execution |
| Simultaneity | Apparent (illusion) | Real |
| Typical benefit | Responsiveness with limited hardware | Higher throughput for independent workloads |
Tasks: browser, music player, software update.
| Time slice (single core) | Browser | Music | Update |
|---|---|---|---|
| 1 | Running | Waiting | Waiting |
| 2 | Waiting | Running | Waiting |
| 3 | Waiting | Waiting | Running |
| 4 | Running | Waiting | Waiting |
| Core (multi-core) | Assigned task |
|---|---|
| Core 1 | Browser |
| Core 2 | Music player |
| Core 3 | Software update |
2.1.5(c) Benefits and Drawbacks of Concurrent Processing
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
Here, forcing concurrency is ineffective because later steps cannot begin before earlier outputs exist.
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 |
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