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 the 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 repeats. Given below is a solution to the Cigarette-Smokers Problem. Give initial conditions for the semaphores as well as plausible values for the variables i & j and r & s, such that the agent and smokers are synchronized. Write a couple of sentences on why these initial conditions are necessary and sufficient. Solution: var a: array [0..2] of semaphore (initial condition = } agent: semaphore { initial condition = } agent code rep repeat Set i,j to a value = wait(agent); signal(a[i]); signal(a[j]); until false; smoker code rep repeat Set r,s to a value = wait(a[r]); wait(a[s]); "smoke" signal(agent); until false; Explanation (brief):
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 the 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 repeats. Given below is a solution to the Cigarette-Smokers Problem. Give initial conditions for the semaphores as well as plausible values for the variables i & j and r & s, such that the agent and smokers are synchronized. Write a couple of sentences on why these initial conditions are necessary and sufficient. Solution: var a: array [0..2] of semaphore (initial condition = } agent: semaphore { initial condition = } agent code rep repeat Set i,j to a value = wait(agent); signal(a[i]); signal(a[j]); until false; smoker code rep repeat Set r,s to a value = wait(a[r]); wait(a[s]); "smoke" signal(agent); until false; Explanation (brief):
Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter17: Markov Chains
Section17.4: Classification Of States In A Markov Chain
Problem 1P
Related questions
Question
![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 the 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 repeats.
Given below is a solution to the Cigarette-Smokers Problem. Give initial conditions for the semaphores as
well as plausible values for the variables i & j and r & s, such that the agent and smokers are synchronized.
Write a couple of sentences on why these initial conditions are necessary and sufficient.
Solution:
var a: array [0..2] of semaphore (initial condition = }
agent: semaphore { initial condition = }
agent code
rep
repeat
Set i,j to a value =
wait(agent);
signal(a[i]);
signal(a[j]);
until false;
smoker code
rep
repeat
Set r,s to a value =
wait(a[r]);
wait(a[s]);
"smoke"
signal(agent);
until false;
Explanation (brief):](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F95069adb-9da5-447d-9aa1-8b7142418c79%2Fb60577e0-2c0f-49c6-a14f-98ad0cd7245c%2Fdnduxdd_processed.png&w=3840&q=75)
Transcribed Image Text: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 the 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 repeats.
Given below is a solution to the Cigarette-Smokers Problem. Give initial conditions for the semaphores as
well as plausible values for the variables i & j and r & s, such that the agent and smokers are synchronized.
Write a couple of sentences on why these initial conditions are necessary and sufficient.
Solution:
var a: array [0..2] of semaphore (initial condition = }
agent: semaphore { initial condition = }
agent code
rep
repeat
Set i,j to a value =
wait(agent);
signal(a[i]);
signal(a[j]);
until false;
smoker code
rep
repeat
Set r,s to a value =
wait(a[r]);
wait(a[s]);
"smoke"
signal(agent);
until false;
Explanation (brief):
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

A Guide to SQL
Computer Science
ISBN:
9781111527273
Author:
Philip J. Pratt
Publisher:
Course Technology Ptr