contention: two or more tasks want the same limited resource; deadlock: tasks wait for one another so none can continue
55-minute lesson sequence
0–5 · Retrieve CPU allocation.
5–15 · Act out the two-resource circular wait.
15–25 · Guide the held/requested arrows and distinguish a request from possession.
25–45 · Students justify a prevention rule and compare memory-pressure choices.
45–50 · Challenge “more RAM or more CPU solves every deadlock” using the scenario.
50–55 · Collect a non-deadlock waiting example.
Try before notes
What does the OS allocate when it schedules a process?
Build the idea
Contention means multiple tasks need a limited resource. Some waiting is normal: a printer may finish one job before starting the next. Deadlock is different because a set of tasks wait on one another and none can make progress.
Draw held resources separately from requested resources. A circular chain is easier to see in a diagram than in a long sentence. More CPU time does not release a resource that another blocked process keeps holding.
A consistent resource-request order can prevent a circular wait in this model. Recovery may require cancelling work or releasing resources, with costs such as lost progress. Explain which link your solution breaks.
P holds lock A → wants lock B
Q holds lock B → wants lock A
P waits for Q; Q waits for P
See the method
Process P holds a scanner and waits for a printer. Q holds the printer and waits for the scanner. Neither releases its first resource. This is a circular wait and can deadlock. A possible prevention rule is that all processes request these resources in the same fixed order. Ordinary waiting is not automatically deadlock.
Predict then reveal
P holds file lock A and requests B. Q holds B and requests A. Neither releases a held lock. Explain the blockage.
Reveal reasoning
P cannot get B until Q releases it. Q cannot get A until P releases it. Both keep their first lock, so neither reaches completion. This circular wait is a deadlock in the stated model.
Require every process to request A before B. How does that change this example?
Reveal reasoning
Only one process can acquire A first. A process waiting for A cannot already hold B under the rule. The first process can obtain B, finish and release both; the circular wait shown cannot form.
Work one step together
Read the first task. Each learner predicts the first step privately. Compare the method, then complete one intermediate row or one code iteration together. Do not display a finished workbook answer.
Practice
Draw P, Q, scanner and printer. Label what is held and what is requested. Explain why adding more CPU time alone does not solve this problem. Propose and justify one prevention or recovery approach.
Your turn
Complete the remaining steps of task 1 alone, then the next tasks. Predict before running code. Save your own evidence before comparing.
Practice
Draw P, Q, scanner and printer. Label what is held and what is requested. Explain why adding more CPU time alone does not solve this problem. Propose and justify one prevention or recovery approach.
Two apps need more RAM than is available. Explain the OS roles in allocation and protection. Compare waiting, moving some inactive pages to backing storage, and closing a process. State one cost.
Check and explain
A long wait is not automatically deadlock. Ask whether some task can still progress and release the resource.
Point to the first step, row, condition or requirement that supports your answer. If results differ, find the first different state and repair one cause.
Show what you know
Give a waiting example that is not deadlock.
HL challenge when ready
Why can repeatedly swapping memory pages harm performance?
Week 4 homework
Show working. Keep code and output. Stop at 25 minutes and mark where you reached.
All jobs arrive at 0 in order A,B. A needs 5 units and B needs 2. Draw FCFS and round robin with quantum 2. Ignore switch cost. Give completion times. Python retrieval: start queue = ["A","B","C"]. Move unfinished A from front to back. Predict, then print the queue.
A device generates rare events while its controller sleeps. Recommend polling or interrupts with one benefit and one limitation.
Explain one deadlock using two processes and two resources. Give a change that breaks the problem.
Explain why a bytecode interpreter and a compiler can both be part of one language implementation.
Spend about 3 minutes on each during practice time. Predict, run, change one thing, then explain. These prompts do not add homework.
A starter is runnable code to explore or complete. If the playground restores your saved code, the linked starter is selected in Example: use Load example when ready. Download your work before confirming replacement.
Prompt 1
Model a resource that can have only one owner. Test an occupied and a free resource.
No imports needed.
Hint and starter code
Contention means multiple tasks want the same limited resource. None marks no owner here.
# Contention means multiple tasks want the same limited resource.
owner = None
requester = "A"
if owner is None:
owner = requester
print(owner)
Detect a two-task circular wait. Change one dependency to break the cycle.
No imports needed.
Hint and starter code
Deadlock means tasks cannot progress because each waits for a resource held by another. This checks only a two-task model.
# Deadlock means tasks cannot progress because each waits for a resource held by another.
waiting_for = {"A": "B", "B": "A"}
print(waiting_for.get(waiting_for["A"]) == "A")