Question: You are asked to implement a simple main program with 1 ( one ) thread that we call provider and 2 6 0 ( two
You are asked to implement a simple main program with one thread that we call provider and twohundreds and sixty threads that we call buyers Design and implement a program that will handle the synchronization of the provider threads and the buyers threads. The program should ensure that the provider thread continuously and repeatedly produces different integers here representing items prints them on the screen, and writes them in a buffer of size x x that you select. Your program also ensures only one buyerthread at a time buys an item represented by an integer from the same buffer and prints it on the screen. The other buyers threads should sleep for some time while the thread buyer is buying. When a thread wakes up it tries to buy an integer from the buffer. 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 providers should not stop providing items ie numbers representing items Make sure that the provider gets a chance to insert items ie numbers in the empty buffer locations where the buyers buy items from nonempty buffer locations. Make sure that each buyer can buy an item from a nonempty buffer location. Only one thread from either the provider thread or the buyer threads can access a buffer location at a time. Your program should have one commandline argument which specifies the number N of buyer threads. When the program starts, it creates N threads which place themselves in a thread pool. The main program issues the initial notification to the provider thread to start providing integers and then notifies the main program to start doing its job as described above by making sure that the N buyer threads have a chance to buy items represented by numbers each buyer thread should at least buy one item
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
