Question: Implement a simple program to illustrate one producer and one consumer problem. The producer will produce 100 messages for the consumer to consume. Use an

Implement a simple program to illustrate one producer and one consumer problem. The producer will produce 100 messages for the consumer to consume. Use an array of 10 slots to hold the contents of the buffer. The producer should send a sequence of integers to the consumer. Specifically, it should send the sequence 1, 2, 3, ..., 100, in that order. The consumer should receive them and check that it has indeed received exactly that sequence, in that order. Implement the program in two ways. 1. not thread-safe, not protecting the buffer; 2. using mechanism to protect the critical sections while they are updated. Figure 2-32 (page 138) of the textbook gives a solution for a single buffer producer-consumer problem using semaphores and conditional variable. Figure 2-35 gives a Java solution using monitors. You may construct your program based on these examples. Assume that it takes a random time between (0, 1) second to produce an item, and (0, 1) second to consumer an item. Notes: 1. You may use any programming language, as long as there is a way to to turn off protection on synchronization; 2. You may increase the number of producers and consumers for additional bonuses;

i NEED THE BONUS AS WELL.tHANKYOU

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!