Question: **You may use C or Java and any synchronization methods to implement the solutions of the Producer and Consumer Problem.** **You may implement the producer
**You may use C or Java and any synchronization methods to implement the solutions of the Producer and Consumer Problem.** **You may implement the producer and consumer on separate threads or processes.** **Producer-Consumer Problem** In this project, you will design a programming solution to the bounded-buffer problem using the producer and consumer processes. For example, in your program, the solution uses three semaphores: empty and full, which count the number of empty and full slots in the buffer, and mutex, which is a binary (or mutual exclusion) semaphore that protects the actual insertion or removal of items in the buffer. For this project, you will use standard counting semaphores for empty and full and a mutex lock, rather than a binary semaphore, to represent mutex. The producer and consumerrunning as separate threadswill move items to and from a buffer that is synchronized with the empty, full, and mutex structures. You may use any synchronization methods for this project. **The Buffer** Internally, the buffer will consist of a **fixed-size (size = 7)** array of type buffer item. The array of buffer item objects will be manipulated as a circular queue. The definition of buffer item, along with the size of the buffer, can be stored in a header file such as the following: /* buffer.h */ typedef int buffer item; #define BUFFER SIZE 7 The buffer will be manipulated with two functions, insert item() and remove item(), which are called by the producer and consumer threads, respectively. The buffer will also require an initialization function that initializes the mutual-exclusion object mutex along with the empty and full semaphores. The main() function will initialize the buffer and create the separate producer and consumer threads. Once it has created the producer and consumer threads, the main() function will sleep for a period of time and, upon awakening, will terminate the application. The main() function will be passed three parameters on the command line: 1. How long to sleep before terminating 2. The number of producer threads 3. The number of consumer threads #include "buffer.h" int main(int argc, char *argv[]) { /* 1. Get command line arguments argv[1],argv[2],argv[3] */ /* 2. Initialize buffer */ /* 3. Create producer thread(s) */ /* 4. Create consumer thread(s) */ /* 5. Sleep */ /* 6. Exit */ } **The Producer and Consumer Threads** The producer thread will alternate between sleeping for a random period of time and inserting a random integer into the buffer. Random numbers will be produced using the rand() function, which produces random integers between 0 and RAND MAX. The consumer will also sleep for a random period of time and, upon awakening, will attempt to remove an item from the buffer.
please give c code with output.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
