Lab 3 · Locks & Deadlock Prevention
Difficulty: Intermediate Time: 60 minutes Topics: ReentrantLock, tryLock, Condition, deadlock
Objectives
- ✅ Use ReentrantLock with proper try-finally
- ✅ Implement timeout-based lock acquisition
- ✅ Demonstrate and prevent deadlock
- ✅ Use Condition variables for coordination
Key Exercises
Exercise 1: Basic ReentrantLock usage Exercise 2: Lock with timeout (tryLock) Exercise 3: Demonstrate deadlock scenario Exercise 4: Prevent deadlock with lock ordering Exercise 5: Use Condition variables for producer-consumer