Question: 2- From the following code, answer these questions a- What is the role of the mutex? b-What is the role of condition variable condp? c-

 2- From the following code, answer these questions a- What is

the role of the mutex? b-What is the role of condition variable

condp? c- What is the role of condition variable condc? d- Why

2- From the following code, answer these questions a- What is the role of the mutex? b-What is the role of condition variable condp? c- What is the role of condition variable condc? d- Why there is a while loop in lines a and b instead of a simple if statement? e- What is the NULL for in line c? Which parameter is affected? * Solution to Producer Consumer Problem * Using Ptheads, a mutex and condition variables * From Tanenbaum, Modern Operating Systems, 3rd Ed. * In this version the buffer is a single number The producer is putting numbers into the shared buffer (in this case sequentially) And the consumer is taking them out. If the buffer contains zero, that indicates that the buffer is empty Any other value is valid. #include # include #define MAX 10000000000 /*Numbers to produce */ pthread mutex t the mutex pthread cond t condc, condp; int buffer 0 2- From the following code, answer these questions a- What is the role of the mutex? b-What is the role of condition variable condp? c- What is the role of condition variable condc? d- Why there is a while loop in lines a and b instead of a simple if statement? e- What is the NULL for in line c? Which parameter is affected? * Solution to Producer Consumer Problem * Using Ptheads, a mutex and condition variables * From Tanenbaum, Modern Operating Systems, 3rd Ed. * In this version the buffer is a single number The producer is putting numbers into the shared buffer (in this case sequentially) And the consumer is taking them out. If the buffer contains zero, that indicates that the buffer is empty Any other value is valid. #include # include #define MAX 10000000000 /*Numbers to produce */ pthread mutex t the mutex pthread cond t condc, condp; int buffer 0

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!