Doing many things at once
Concurrency versus parallelism, race conditions and locks.
Planned. This module is part of the plan and is not written yet.
Why it matters
If two stations update the same attendance count at the same moment, one update can be lost. That is a race condition, and locks prevent it.
Draft outline · in review- For
- Level 14–15 · 100 Level to 200 Level
- Inside
- 5 lessons and a test · about 90 minutes
- Topic
- Concurrency · extension, 3 of 4
Inside the module.
5 lessons in order, about 90 minutes in all, then a short test. Learners go at their own pace; the minutes are a guide, not a timetable.
Draft outline · in review
Lesson 1: Concurrency and parallelism
Taking turns on one core, compared with truly running at once on several cores.
Explain15 min, from minute 0
Lesson 2: Threads in Python
Start threads, wait for them with join() and see their output interleave.
Worked example15 min, from minute 15
Lesson 3: Making a race happen
Run two threads that increment one counter and look for lost updates.
Investigate20 min, from minute 30
Lesson 4: Fixing it with a lock
Protect the shared counter with threading.Lock.
Worked example20 min, from minute 50
Lesson 5: Deadlock
Make two locks deadlock, then fix it by always taking locks in the same order.
Practice20 min, from minute 70
End-of-module test
Explain the difference between concurrency and parallelism, and find and fix a race condition with a lock.
Mastered at 85% or more. Retake it until you pass; nothing is lost, and each try gives feedback.
Already know it? A Challenge Test (planned) clears the whole module: 90% overall, no objective below 75%.
Last stageafter about 90 min
Practicalities
Draft outline · in reviewBuilt to run offline
Planned to run on the Lantern's own computer, with no internet needed.
Languages
Planned first in English; every module aims to reach all of the Lantern's languages.
Try a question.
One question from the module, as a learner would meet it. Have a go, then open the worked solution a step at a time.
Draft outline · in review
Two threads each run this 100,000 times on the same global count, which starts at 0: count += 1 The total can come out below 200,000. Why, and how do you fix it?
Work it out on paper first, then show the answer and mark it yourself.
Particulars
Where it sits
What a learner can do after it
- Explain the difference between concurrency and parallelism.
- Spot a race condition and fix it with a lock.
Needs first
We suggest first (never a lock)
Level
Level 14–15 · 100 Level to 200 Level
Level mappings are approximate. A qualified teacher or lecturer in each country must check them before they appear in the app. Levels 13–18 describe the content, not the learner: “Level 15” means material usually taught in a second-year university course, whoever chooses to learn it.
Difficulty for its level
3 of 4 · Extension
Time
About 90 minutes
Alignments
- Aligned to CS2023partial · in reviewCS2023 Parallel and Distributed Computing: concurrency (descriptive ref)
Alignment in review until a qualified teacher or lecturer checks it. No exam body, university or vendor endorses us; learners still sit the real exam. University-level modules give knowledge, not university credit.
Challenge Test
Planned: a Challenge Test to prove you know it and skip it. Pass at 90% overall, with no objective below 75%.
University courses it previews
Computer Science, Software Engineering
On these pathways
The route here.
Everything this module builds on, drawn as a route from its foundations. Solid lanes must be mastered first, or cleared by a Challenge Test; dashed lanes are suggestions that never lock anything.
- CO-BLK-SEQ-01 Instructions in order, Level 1–4, Coding. Planned.
- CO-BLK-SEQ-01Instructions in orderCoding · Primary 1 to Primary 4 (Level 1–4) · Planned
- CO-BLK-LOP-01 Repeat blocks, Level 3–5, Coding. Sample lesson in the demo.
- CO-BLK-LOP-01Repeat blocksCoding · Primary 3 to Primary 5 (Level 3–5) · Sample lesson in the demo Needs Instructions in order (required).Try the sample lesson: Repeat blocks
- DS-CMP-TYP-01 The home row, Level 3–6, Digital skills. Planned.
- DS-CMP-TYP-01The home rowDigital skills · Primary 3 to Primary 6 (Level 3–6) · Planned · recommended
- CO-BLK-CND-01 If this, then that, Level 3–6, Coding. Planned.
- CO-BLK-CND-01If this, then thatCoding · Primary 3 to Primary 6 (Level 3–6) · Planned · recommended
- CO-BLK-LOP-02 Patterns with loops, Level 4–6, Coding. Planned.
- CO-BLK-LOP-02Patterns with loopsCoding · Primary 4 to Primary 6 (Level 4–6) · Planned Needs Repeat blocks (required).
- MA-ARI-ORD-01 Order of operations, Level 5–6, Maths. Planned.
- MA-ARI-ORD-01Order of operationsMaths · Primary 5 to Primary 6 (Level 5–6) · Planned · recommended
- CO-BLK-LOP-03 Loops inside loops, Level 5–7, Coding. Planned.
- CO-BLK-LOP-03Loops inside loopsCoding · Primary 5 to JSS 1 (Level 5–7) · Planned · recommended
- CO-PRG-PYB-01 Your first Python program, Level 7–9, Coding. Planned.
- CO-PRG-PYB-01Your first Python programCoding · JSS 1 to JSS 3 (BECE) (Level 7–9) · Planned Needs Patterns with loops (required), The home row (recommended).
- CO-PRG-PYB-02 Variables, Level 7–9, Coding. Sample lesson in the demo.
- CO-PRG-PYB-02VariablesCoding · JSS 1 to JSS 3 (BECE) (Level 7–9) · Sample lesson in the demo Needs Your first Python program (required).Try the sample lesson: Variables
- CO-PRG-PYB-03 Numbers and calculations, Level 7–9, Coding. Planned.
- CO-PRG-PYB-03Numbers and calculationsCoding · JSS 1 to JSS 3 (BECE) (Level 7–9) · Planned Needs Variables (required), Order of operations (recommended).
- MA-ALG-FRM-01 Substituting into formulae, Level 7–8, Maths. Planned.
- MA-ALG-FRM-01Substituting into formulaeMaths · JSS 1 to JSS 2 (Level 7–8) · Planned · recommended
- CO-PRG-PYB-05 Decisions with if, Level 8–10, Coding. Planned.
- CO-PRG-PYB-05Decisions with ifCoding · JSS 2 to SSS 1 (Level 8–10) · Planned Needs Numbers and calculations (required), If this, then that (recommended).
- CO-PRG-PYB-06 Loops in Python, Level 8–10, Coding. Planned.
- CO-PRG-PYB-06Loops in PythonCoding · JSS 2 to SSS 1 (Level 8–10) · Planned Needs Decisions with if (required), Loops inside loops (recommended).
- CO-PRG-PYF-01 Defining functions, Level 8–11, Coding. Planned.
- CO-PRG-PYF-01Defining functionsCoding · JSS 2 to SSS 2 (Level 8–11) · Planned Needs Loops in Python (required).
- CO-PRG-PYB-07 Lists, Level 8–10, Coding. Planned.
- CO-SYS-OPS-01 What an operating system does, Level 8–11, Coding. Planned.
- CO-SYS-OPS-01What an operating system doesCoding · JSS 2 to SSS 2 (Level 8–11) · Planned · recommended
- CO-PRG-PYF-02Parameters and return valuesCoding · JSS 3 (BECE) to SSS 2 (Level 9–11) · Planned Needs Defining functions (required), Substituting into formulae (recommended).
- CO-ALG-SRT-01Linear searchCoding · JSS 3 (BECE) to SSS 2 (Level 9–11) · Planned Needs Parameters and return values (required), Lists (required).
- CO-PRG-PYF-03ScopeCoding · JSS 3 (BECE) to SSS 2 (Level 9–11) · Planned Needs Parameters and return values (required).
- CO-PRG-PYF-04Breaking problems into functionsCoding · JSS 3 (BECE) to SSS 3 (WASSCE) (Level 9–12) · Planned Needs Parameters and return values (required), Lists (required).
- CO-ALG-SRT-03Simple sortsCoding · SSS 1 to SSS 3 (WASSCE) (Level 10–12) · Planned Needs Linear search (required).
- CO-ALG-SRT-02Binary searchCoding · SSS 1 to SSS 3 (WASSCE) (Level 10–12) · Planned Needs Linear search (required).
- CO-PRG-PYF-05RecursionCoding · SSS 2 to A level / JUPEB / foundation year (Level 11–13) · Planned Needs Scope (required).
- CO-ALG-SRT-04Merge sortCoding · SSS 2 to A level / JUPEB / foundation year (Level 11–13) · Planned Needs Simple sorts (required), Recursion (required).
- CO-ALG-SRT-05Comparing algorithmsCoding · SSS 3 (WASSCE) to A level / JUPEB / foundation year (Level 12–13) · Planned Needs Binary search (required), Merge sort (required).
- From here on: Beyond school · university levelCO-DST-CCR-01Doing many things at onceCoding · 100 Level to 200 Level (Level 14–15) · Planned · the destination Needs Breaking problems into functions (required), Comparing algorithms (required), What an operating system does (recommended).
Help light the room where this is learned.
Every route on this map starts in a classroom with 24 stations, a tutor that works offline and a facilitator upstairs. Four are planned and waiting for light.