Skip to content
Ameen Abozaid
Planned lessonMID-004-L07

Deadlocks

  • Lesson 7 of 9
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

recognize and prevent deadlock.

Planned topics

  • Deadlock: threads each hold a lock and wait for another's; none proceeds.
  • Four conditions: mutual exclusion, hold and wait, no preemption, circular wait.
  • Prevention: acquire locks in a global order; hold fewer locks; use tryLock with timeout.
  • Livelock and starvation are related: threads busy but no progress, or never scheduled.
  • Thread dumps report deadlocks explicitly.
Draft outline details

Demonstration

transfer(a,b) and transfer(b,a) locking in opposite order; fix by locking the lower ID first.

Check your understanding

What simple rule prevents circular wait?

Show answer

Always acquire locks in the same global order.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.