1) For the following “Producer-consumer Problem using Semaphores”, (a) Will there be any deadlock if the order of the downs were switched, for the producer or for the consumer individually as well as together (so, 3 combinations)? Explain. Now, (b) similarly consider the order of ups and show (3 combinations again) – when you assume that the ups are switched then keep the downs intact (not switched).
1) For the following “Producer-consumer Problem using Semaphores”, (a) Will there be any deadlock if the order of the downs were switched, for the producer or for the consumer individually as well as together (so, 3 combinations)? Explain. Now, (b) similarly consider the order of ups and show (3 combinations again) – when you assume that the ups are switched then keep the downs intact (not switched).
Chapter8: Advanced Method Concepts
Section: Chapter Questions
Problem 7RQ
Related questions
Question
1) For the following “Producer-consumer Problem using Semaphores”, (a) Will there be any deadlock if the order of the downs were switched, for the producer or for the consumer individually as well as together (so, 3 combinations)? Explain. Now, (b) similarly consider the order of ups and show (3 combinations again) – when you assume that the ups are switched then keep the downs intact (not switched).
![semaphore mutex = 1; /* binary semaphore providing mutual exclusion */
semaphore empty = N; /* counting semaphore, counts empty buffer slots */
semaphore full = 0; /* counting semaphore, counts full buffer slots */
void producer(void)
{
while(TRUE)
}
{
int item = produce_item();
down(&empty);
down(&mutex); // Enter CR
insert_item(item); //put in buffer
up(&mutex); // Leave CR
up(&full);
void consumer(void)
{
while(TRUE)
down(&full);
down(&mutex); // Enter CR
int item = remove_item(); //remove item from buffer
up(&mutex); // Leave CR
up(&empty);
consume_item(item); // do something with it
{
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fb39e8419-2e68-43b3-b501-0415bdeb01b5%2Faa2a7962-4ee3-4767-a656-39d19d6d6d88%2F0dac9k_processed.png&w=3840&q=75)
Transcribed Image Text:semaphore mutex = 1; /* binary semaphore providing mutual exclusion */
semaphore empty = N; /* counting semaphore, counts empty buffer slots */
semaphore full = 0; /* counting semaphore, counts full buffer slots */
void producer(void)
{
while(TRUE)
}
{
int item = produce_item();
down(&empty);
down(&mutex); // Enter CR
insert_item(item); //put in buffer
up(&mutex); // Leave CR
up(&full);
void consumer(void)
{
while(TRUE)
down(&full);
down(&mutex); // Enter CR
int item = remove_item(); //remove item from buffer
up(&mutex); // Leave CR
up(&empty);
consume_item(item); // do something with it
{
}
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,