Research and Program Producer-ConsumerProblem
In this assignment you will design a programming solution to thebounded-buffer problem using the producer and consumer processesshown in the lecture notes. The solution presented in the notesuses three semaphores: empty and full, which count the number ofempty and full slots in the buffer, and mutex, which is a binarysemaphore that protects the actual insertion or removal of items inthe buffer. For this assignment, standard counting semaphores willbe used for empty and full, Use a mutex lock, rather than a binarysemaphore, to represent the mutex. The producer andconsumer—running as separate threads will move items to and from abuffer that is synchronized with these empty, full, and mutexstructures.
The buffer
Internally, the buffer will consist of a fixed-size array oftype buffer item (which will be defined using typedef). The arrayof buffer _item objects will be manipulated as a circularqueue.
The buffer will be manipulated with two functions, insert_item()and remove_item(), which are called by the producer and consumerthreads, respectively.
The insert_item() and remove_item) functions will synchronizethe producer and consumer using the algorithms outlined in theclass lecture. The buffer will also require an initializationfunction that initializes the mutual exclusion object mutex alongwith the empty and full semaphores.
The main() function will initialize the buffer and create theseparate producer and consumer threads. Once it has created theproducer and consumer threads, the main() function will sleep for aperiod of time and upon awakening, will terminate the application.The main() function will be passed three parameters on the commandline:
a.  How long to sleep before terminating
b. The number of producer threads
c. The number of consumer threads
Producer and Consumer Threads
The producer thread will alternate between sleeping for a randomperiod of time and inserting a random integer into the buffer.Random numbers will be produced using the rand() function, whichproduces random integers between 0 and RAND_MAX. The consumer willalso sleep for a random period of time and, upon wakening, willattempt to remove an item from the buffer.
Mutex Locks
The code should have commands to create, acquire, and releasemutex locks.
Assumption: You will use the book and lecture notes for baseinfo to complete the program. You will conduct your own research tofill in any knowledge holes.
Use POSIX Pthreads.