Question: 5. More practice with synchronization Consider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigarette and then smokes

 5. More practice with synchronization Consider a system with three smokerprocesses and one agent process. Each smoker continuously rolls a cigarette and

5. More practice with synchronization Consider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigarette and then smokes it. But to roll and smoke a cigarette, the smoker needs three ingredients: tobacco, paper, and matches. One of the smoker processes has paper, another has tobacco, and the third has matches. The agent has an infinite supply of all three materials. The agent places two of the ingredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts out another two of the three ingredients, and the cycle repcats. Assume the agent calls the procedure void chooseIngredients (int *paper, int *tobacco, int *match); to randomly select 2 of the 3 ingredients. The routine randomly sets 2 of the ints to "1" and one of them to "O". You don't have to write this routine. Write a program to synchronizc the agent and smokers: 5.1. What synchronization and state variables will you usc in this problem? (For cach variable, indicate the variable's type, the variable's name, its initial valuc (if any), and a short comment describing the variable's purpose.) Variable Name Variable Type Initial Value Description 5.2. Write the routines Agent) and matchSmoker ) (the routine for the smoker that has lots of matches). You don't have to write the routines paperSmoker () or tobaccoSmoker), but your solution should be general enough so that those routines would be simple variations of matchSmoker 5. More practice with synchronization Consider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigaretre and then smokes it. But to roll and smoke a cigarette, the smoker needs three ingredients: tobacco, paper, and matches. Oue of the smoker processes has paper, another has tobacco, and the third has matches. The agent has an infinite supply of all three materials The agent places two of the ingredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts out another two of the three ingredients, aud the cycle repeats Assume the agent calls the procedure void choo seIngredients(int *paper , int *tobacco, int *match); to randomly select 2 of the 3 ingredients. The routine randomly sets 2 of the ints to "I" and one of them to "O". You don't have to write this routine. Write a program to synchronize the agent and smokers 5.1. What synchronization and state variables will you use in this problem? (For each variable, indicate the variable's type, the variable's name, its initial value (if any), and a short comment describing the variable's purpose.) Variable Name VariableTye Initial Value Description 5.2. Write the routines Agent) and natchSnoker) (the routine for the smoker that has lots of matches). You don't have to write thc routines paperSmoker) or tobsccosmaker), but your solution should be general enough so that those routines would be simple variations of match5moker()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!