Question
Create a semaphore-based solution to the producer-consumer problem as outlined in section 6.6.1,the Synchronization slides, and the pthreadSemaphore slide. 1) Create a global array of
Create a semaphore-based solution to the producer-consumer problem as outlined in section 6.6.1,the Synchronization slides, and the pthreadSemaphore slide. 1) Create a global array of integers of size 5. 2) Create five producer threads and five consumer threads. The producer threads fill up the array with sequential numbers while the consumers consume the arrays and displays the numbers. 3) Use a semaphore (empty) to block the producers when the buffer is full and use a different semaphore (full) to block the consumers when the buffer is empty. The producer needs to signal the full semaphore and the consumer needs to signal the empty semaphore. 4) Use a consumer mutex to protect the consumers critical section and a producer mutex to protect the producers critical section. 5) Both the producer and consumer threads should be running in infinite loops (while(1)). The consumer will exit the entire process when it consumes the integer 1000.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started