Question: The bounded-buffer problems (aka the producer-consumer problem) is a classic example of concurrent access to a shared resource. A bounded buffer lets multiple producer threads

 The bounded-buffer problems (aka the producer-consumer problem) is a classic example

of concurrent access to a shared resource. A bounded buffer lets multiple

The bounded-buffer problems (aka the producer-consumer problem) is a classic example of concurrent access to a shared resource. A bounded buffer lets multiple producer threads and multiple consumer threads share a single shared buffer. Producers write data to the buffer by invoking put() method and consumers read data from the buffer by calling get() method. The following implementation for producer and consumer correctly works for a single producer and a single consumer thread for the bounded buffer of the size one integer variable. However, the implementation does not properly work for two producer threads and a single consumer thread. Suppose put() and get() methods are correctly implemented, 1. Explain why the following implementation is broken for more than one producer threads, and 2. Fix the problem to make the corrected implementation work for two producer threads and a single consumer thread. If you need, you can refer to P thread reference link. int buffer; int count =0; void put(int value) \{ count =1; buffer = value; \} int get() \{ count =0; return buffer; \} pthread_mutex_t m= PTHREAD_MUTEX_INITIALIZER; pthread_cond_t c= PTHREAD_COND_INITIALIZER; void *producer (void *arg) \{ int i; int loops = (int) arg; for (i=0; i

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!