Skip to main content

Practice · 4 of 4

Deadlock or Safe?

CHALLENGE
Difficulty: advanced+25 XP

Implement const char *lock_verdict(int kind): 0 two threads acquire mutexes A then B, and B then A → a deadlock risk; 1 all threads acquire A then B → safe; 2 second lock taken with try-lock, released and retried on failure → safe; 3 blocking acquisition of a second lock while an outer lock is held by the same thread that another thread needs first → a deadlock risk; 4 a single mutex, no nesting → safe.

Back to lesson: Practice: Synchronization Drills