The Cigarette Smokers Problem:: Os PBL
The Cigarette Smokers Problem:: Os PBL
Smokers
Problem:
OS PBL
Introduction:
1. Non-deterministic Selection:
Agent randomly places two
items
2. Smoker's Decision: Smoker
with the missing item smokes
3. Deadlock Risk: Wrong smoker
waking up causes deadlock
Trick of the Problem
• Animation video.
Potential Solutions:
- 1. Using Condition Variables
- Smokers' Logic:
- Each smoker thread waits on a specific condition.
- The condition depends on whether the two resources placed by the agent
match the two they need.
- 2. Semaphore-based Solutions
- Approach:
- Although semaphores alone are not suitable, using a combination of
semaphores and condition variables could solve the synchronization issue.
- When the agent places two ingredients on the table, a semaphore signals the
specific smoker thread that can consume the items.
- 3. Monitors and Mutex Locks
- Monitor Approach:
- Encapsulate the agent and smokers in a monitor.
- Use mutual exclusion to ensure that only the smoker who has the right
ingredients wakes up to consume the resources.
Conclusion
• Key Takeaways: