Question: Making use of Semaphores and Pthreads, create a program in C to handle the following. You are asked to implement 4 (four) threads that we

Making use of Semaphores and Pthreads, create a program in C to handle the following.

You are asked to implement 4 (four) threads that we call "providers" and a simple-main-program for 260 (two-hundred and sixty) threads that we call "buyers". The providers' threads produce different integer-numbers and put them in a queue. Design and implement a program that will handle the synchronization of providers' threads as well as buyers' threads. Basically the program should make sure that only one provider inserts items (integer representing number of items) and prints it on the screen. The other provider threads should sleep for some time while the thread buyer is buying. When a thread wakes up, it tries to by an integer from the queue. Make sure that each and all buyers get a chance to buy an item, represented by a number. No buyer should make the other ones starve. The provider should not stop providing items (i.e. numbers representing items). Make sure that each and all of the providers get a chance to insert items (i.e. numbers). Hint: You can use a minimum of 10 buffers.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!