CSC33200- Lab 6 – Cigarette Smokers Problem solved

35.00 $

Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment


5/5 - (1 vote)

Problem Description
Consider a system with 3 smoker processes and 1 agent process. Each smoker continuously rolls a cigarette and then smokes it. The smoker needs three ingredients: tobacco, paper, and matches. One of the smokers has paper, another has tobacco, and the third has matches. The agent has an infinite supply of all three materials and (randomly) places two of the ingredients on the table each time. 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 repeats.
TO DO: Write a program to synchronize the agent and smoker processes using the pthread library and pthread_mutex.
• Although the problem description gives the agent an infinite supply of ingredients, you may set a
reasonable finite number of iterations.
• You need to include an explanation of how your code succeeds in synchronizing the agent and the smokers. Provide output showing the sequence of events for several iterations.
• See the pseudocode below.
Zip your source & explanation text files into a single folder as: task6_lastname .zip. Email your zip file with the subject line, “Task 6 – CSc332G- lastname “.
Cigarette Smoker’s Problem as presented by Prof. Jeffrey Hollingsworth, University of Maryland
There are four processes in this problem: three smoker processes and an agent process. Each of the smoker processes will make a cigarette and smoke it. To make a cigarette requires tobacco, paper, and matches. Each smoker process has one of the three items. I.e., one process has tobacco, another has paper, and a third has matches. The agent has an infinite supply of all three. The agent places two of the three items on the table, and the smoker that has the third item makes the cigarette. Synchronize the processes.

Please note this is the formulation of the problem used in recent OS texbooks, but not the problem as originally described by Parnas in CACM March 1975.