Skip to content

Benefits and Drawbacks of Concurrent Processing

2.1.5 Thinking concurrently · Paper 2 · 8 flashcards · 6 questions

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.
pseudocode
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

Shared Data: Race Conditions, Record Locking and Deadlock

Definition
A thread is a sequence of instructions within a program that can run independently of the others. A concurrent program has several threads, which often need to use the same data.
TermMeaningExample in an online ticket system
Race conditionTwo processes read and change the same data at overlapping times, so the result depends on which finishes first and one update can be lostTwo customers are both shown the last seat as free and both buy it
Record lockingOnly one process at a time is allowed to change a record; the others must wait until it is releasedThe seat record is locked while the first customer pays
DeadlockTwo processes each hold a resource that the other needs, so neither can ever continueOne 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
Key Point
Trade-offs to weigh up in a given situation:
• 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

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