Create a c program using multithreading and semaphore
Budget: $10 – $30 USD
--->Create a global array of integers of size 5.
--->Create five producer threads and five consumer threads. The producer threads will fill up the array with sequential numbers while the consumers will consume the arrays and display the numbers.
--->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.
--->Use a consumer mutex lock to protect the consumer’s critical section and a producer mutex to protect the producer’s critical section.
--->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.
The 5 producers will be inserting numbers, in order, from 0-1000. So the first producer will produce 0, the second will produce 1, and so forth, until the array is filled (protected with the empty semaphore). The consumers will be doing the opposite: as long as there are items in the array (this is the job of the full semaphore), they should be removing the items, signaling the producers and allowing another item to be produced; e.g., when 0 is removed, the next producer will fill it with 5. The first consumer will remove 0 and display it, the second will remove 1 and display it, etc. The output will be a series of values:
0
1
2
3
4
... all the way to 1000.
Submit three files (prod_cons_NAME.c , README.txt, and Makefile)
--->Create five producer threads and five consumer threads. The producer threads will fill up the array with sequential numbers while the consumers will consume the arrays and display the numbers.
--->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.
--->Use a consumer mutex lock to protect the consumer’s critical section and a producer mutex to protect the producer’s critical section.
--->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.
The 5 producers will be inserting numbers, in order, from 0-1000. So the first producer will produce 0, the second will produce 1, and so forth, until the array is filled (protected with the empty semaphore). The consumers will be doing the opposite: as long as there are items in the array (this is the job of the full semaphore), they should be removing the items, signaling the producers and allowing another item to be produced; e.g., when 0 is removed, the next producer will fill it with 5. The first consumer will remove 0 and display it, the second will remove 1 and display it, etc. The output will be a series of values:
0
1
2
3
4
... all the way to 1000.
Submit three files (prod_cons_NAME.c , README.txt, and Makefile)