Question: This project will demonstrate two processes acting as a producer and consumer in the language C + + . The program should create named semaphores

This project will demonstrate two processes acting as a producer and consumer in the language C++.
The program should create named semaphores which both parent and child can access. It should then create a block of shared memory that will serve as a shared buffer. The producer should begin placing numbers 1 to 100 into the shared buffer while the consumer begins getting the numbers out of the buffer and printing them. The buffer should hold 5 numbers. The actions should be coordinated using semaphores, as shown in slides 34 and 35 of the chapter 6 slides.
Producer Process:
do {
.../* produce an item in next_produced */
...
wait(empty);
wait(mutex);
.../* add next produced to the buffer */
...
signal(mutex);
signal(full);
} while (true);
Consumer Process:
Do {
wait(full);
wait(mutex);
.../* remove an item from buffer to next_consumed */
...
signal(mutex);
signal(empty);
.../* consume the item in next consumed */
...} while (true);

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 Programming Questions!