Question: 2. (10 points) Consider 3 smokers and an agent. Each smoker wants to roll a cigarette and smoke it immediately. To smoke a cigarette, the

2. (10 points) Consider 3 smokers and an agent. Each smoker wants to roll a cigarette and smoke it immediately. To smoke a cigarette, the smoker needs three ingredients paper, tobacco, and a match. Each smoker has only one ingredient smoker 1 has paper, smoker 2 has tobacco, and smoker 3 has matches. The agent has access to all three items. However, at a time the agent selects two items randomly and puts them on the table. The smoker with the remaining ingredients immediately takes them, rolls, and smokes. When finished, the agent is woken up who then places another two randomly selected items on the table. Write the code for the agent and smokers using Semaphores
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
