The Cigarette-SmokersProblem. Consider a system with three smoker processes and one agent process.Each smoker continuously rolls a cigarette and then smokes it. But to roll andsmoke a cigarette, the smoker needs three ingredients: tobacco, paper, and matches. One of the smoker processes has paper, another has tobacco, and thethird has matches. The agent has an infinite supply of all three materials. Theagent places two of the ingredients on the table. The smoker who has theremaining ingredient then makes and smokes a cigarette, signaling the agent oncompletion. The agent then puts out another two of the three ingredients, andthe cycle repeats. Write a program to synchronize the agent and the smokers.
觉得自己写得好烂啊……请各路大神指正
String material [3]={“Tobacco”, ” paper”,”matches”}; //数组用于存放供应者供应的材料
String self [3]= {“Tobacco”, ” paper”,”matches”}; //数组用于存放当前吸烟者持有的材料
Semaphore mutex =1, producer=0, smoker=0; //三个信号量