The Smokers Problem
Three smokers are sitting around a table.Only one person can smoke at a time . To smoke a smoker needs three ingredients : tobacco ,paper and a match. Each smoker has an infinite supply of just one of these ingredients and must wait for the other two to be made available by a smoke’s agent.The smoker’s agent has an infinite supply of all three ingredients. The agent places two ingredients on the table and waits for a smoker to make a cigarette and smoke it .When the smoker is finished smoking it notifies the agent that another round of ingredients should be placed on the table to allow smoking to continue.
In this way smokers can continue smoking in some order forever!
Your task is to write a program that simulate the behaviour of the smokers and the smoker’s agent.
Hint: Think of the smokers and the agent as threads that share a table .