FOR FREE CONTENT

Cigarette Smokers problem

 

In this problem, four processes are there, three smokers and one supplier process. Cigarette requires tobacco, paper, and matches. Three smokers have the ability to supply one of the three items (tobacco, paper, matches) and the supplier has the ability to supply all three ingredients (tobacco, paper, matches). 

 

Now, agents palaces two random ingredients on the table and the smokers sitting around the table supply the third ingredient to makes the cigarette.

 

Once the cigarette has been finished, again same procedure will be applied to make the cigarette. 

 

This problem can lead to a deadlock or race-around condition. Because let supplier places tobacco and matches on the table and it selects one of the smokers who can supply matches and go to sleep. Now here selected smoker unable to make their cigarette because smoker who can supply paper was not selected. Now, the supplier is in sleep after ingredients and smokers also go to sleep because they can’t make a cigarette. All processes going to sleep forever which leads to a deadlock.

 

Solutions

 

So, the algorithm is very simple where three smokers make a cigarette and consume it. If they can't make the cigarette, then they go to sleep.

 

The supplier process provides any of two ingredients and wakes the proper smoker and goes to sleep. 

 

Here four semaphores are used for three smokers and one supplier. One semaphore is used for mutual exclusion i.e. mutex.