Producer-Consumer Problem Variation. In class, we reviewed the Producer-Consumer problem, which used semaphores to control access to a bounded buffer where a Producer process would produce data items and add them to the buffer and one Consumer would remove data items from the buffer and consume them (please refer to slide 18 in the Week 9 PowerPoint or Figure 5.16 in the course textbook for the pseudocode for this problem). As a variation of that problem, assume the bounded buffer size is 12. Assume the Producer process enters 3 items at a time into the buffer. It will only do this if there are at least 3 empty spots in the buffer. Assume the Consumer process will remove items 2 at a time, and will only do so if there are at least 2 items in the buffer. In addition to the Producer and Consumer processes, assume there is a third Hybrid process. Each time it accesses the buffer its role changes. One time it is a Producer entering a single item, and the next time it is a Consumer removing a single item. Write pseudocode similar to Figure 5.16 in the textbook to handle this situation (make sure you change the values for any semaphores as necessary and provide implementations for the Producer, Consumer, and Hybrid processes).
Producer-Consumer Problem Variation. In class, we reviewed the Producer-Consumer problem, which used semaphores to control access to a bounded buffer where a Producer process would produce data items and add them to the buffer and one Consumer would remove data items from the buffer and consume them (please refer to slide 18 in the Week 9 PowerPoint or Figure 5.16 in the course textbook for the pseudocode for this problem). As a variation of that problem, assume the bounded buffer size is 12. Assume the Producer process enters 3 items at a time into the buffer. It will only do this if there are at least 3 empty spots in the buffer. Assume the Consumer process will remove items 2 at a time, and will only do so if there are at least 2 items in the buffer. In addition to the Producer and Consumer processes, assume there is a third Hybrid process. Each time it accesses the buffer its role changes. One time it is a Producer entering a single item, and the next time it is a Consumer removing a single item. Write pseudocode similar to Figure 5.16 in the textbook to handle this situation (make sure you change the values for any semaphores as necessary and provide implementations for the Producer, Consumer, and Hybrid processes).
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images