H446/02 · Algorithms & ProgrammingSection 2.1

2.1.5 Thinking concurrently

Concurrent processing, how it is achieved, benefits and drawbacks of concurrent systems

📚2.1.5 Thinking Concurrently

2.1.5(a) Concurrent Thinking

Definition
Concurrent thinking is the process of recognising and applying the concept of concurrent processing—executing more than one task at the same time. It involves identifying patterns in problems where concurrency can be applied, allowing for more efficient problem-solving.

Understanding Concurrent Thinking

Worked Example
Worked Example: Recording Car Information

Scenario: for each passing car, record number plate and colour.

ApproachWhat happensTypical outcome
SequentialRecord all plates first, then try colours laterMissing/mismatched data likely
Concurrent thinkingCapture plate + colour together per car eventMore complete and accurate records
Why this helps:
• Better data consistency (plate matches colour)
• More efficient handling of each event
• Less risk of missing information

Key Point
ConceptMeaningExample
Concurrent processingOne core rapidly time-slices between tasksBrowser + music + update on single-core CPU
Multicore processingDifferent cores handle tasks simultaneouslyOne app per core on multi-core CPU
Everyday concurrency patternMultiple active activities with shared resources/timeCooking multiple dishes, supermarket checkout lanes

2.1.5(b) Concurrent Processing

Definition
Concurrent processing involves a computer processor managing multiple tasks by assigning each a portion of processor time. This creates the appearance of tasks running simultaneously, but in reality they are executed sequentially through time-slicing.

Concurrent vs Parallel Processing

Key Point
FeatureConcurrent processingParallel processing
Hardware basisUsually single core/processor time-sharingMultiple cores/processors
Execution styleRapid switching between tasksTrue same-time execution
SimultaneityApparent (illusion)Real
Typical benefitResponsiveness with limited hardwareHigher throughput for independent workloads

Worked Example
Worked Example: Multitasking Computer

Tasks: browser, music player, software update.

Time slice (single core)BrowserMusicUpdate
1RunningWaitingWaiting
2WaitingRunningWaiting
3WaitingWaitingRunning
4RunningWaitingWaiting
Result (concurrent): each task progresses via rapid switching.

Core (multi-core)Assigned task
Core 1Browser
Core 2Music player
Core 3Software update
Result (parallel): tasks run truly simultaneously on different cores.

2.1.5(c) Benefits and Drawbacks of Concurrent Processing

Benefits

Key Point
BenefitWhy it happens
Increased efficiencyCPU can work on another task while one is waiting (e.g. I/O)
Better resource useTime-slicing reduces idle processor time
Improved responsivenessForeground UI can stay active while background work continues

Drawbacks

Key Point
DrawbackWhy it is a problem
Potential delaysMore active tasks means each gets CPU time less often
Context-switch overheadSaving/loading task state reduces useful work time
Higher complexityConcurrency bugs are harder to reason about and test
Limited suitabilityDependency-heavy tasks still require sequential order

Worked Example
When Sequential is Better than Concurrent

Scenario: steps depend on each previous result.
text
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:

SituationBetter approach
Strong step dependenciesSequential
Very small tasksOften sequential (avoid overhead)
Heavy synchronisation needsOften sequential/simpler design
High shared-resource contentionSequential or carefully controlled concurrency

Key Terms Summary

Definition
TermDefinition
Concurrent processingTasks share CPU time slices to appear simultaneous on one processor/core
Parallel processingMultiple processors/cores execute tasks at the same time
Processor time sliceSmall CPU time segment allocated to one task
Context switchingSaving one task's state and restoring another's during task switch

Exam Tip
Exam Tips for Thinking Concurrently:
• 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