Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The purpose of this project is to provide you with some hands-on experience in using standard pthreads library to solve producer-consumer problem. For more information
The purpose of this project is to provide you with some hands-on experience in using standard pthreads library to solve producer-consumer problem. For more information on pthreads, you may review the pthreads Web page and the tutorial from Lawrence Livermore National Lab. In this project, you will design a programming solution to the bounded-buffer problem by using the producer and consumer processes described in process synchronization chapter of your textbook. The producer's job is to generate a piece of data, put it into the buffer and start again. At the same time the consumer is consuming the data one piece at a time. The problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty buffer The solution for the producer is to go to sleep if the buffer is full. The next time the consumer removes an item from the buffer, it wakes up the producer who starts to fill the buffer again. In the same way the consumer goes to sleep if it finds the buffer to be empty. The next time the producer puts data into the buffer, it wakes up the sleeping consumer. The solution can be reached by means of inter-process communication, typically using semaphores. Your solution should avoid any deadlock situation that might occur. The size of the buffer used by the producer and the consumer is 7. The solution presented in the textbook uses three semaphores: empty and full, which count the number of empty and full slots in the buffer, and mutex, which is a binary semaphore that protects the actual insertion or removal of items in the buffer. For this project, standard counting semaphores will be used for empty and full, and a binary semaphore, mutex lock, will be used to represent mutual exclusion. The producer and consumer - running as separate threads - will move random number of items to and from a buffer that is synchronized with these empty, full, and mutex structures. You are required to use the pthread package to solve this problem in this project
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