Operating Systems: C PROGRAM (single standard .c file):
I need to use the concept of POSIX threads, semaphores and mutex locks.
Consider a very small bank: XYZ. This bank has only one cashier (aka bank teller or customer representative) and a small waiting room for any incoming customers while the cashier is busy with other customer. There is a sofa which can only hold 5 people at maximum. The cashier can only serve one customer at any time. When the cashier is serving one customer, other customers have to wait in the sofa. If there are already 5 people waiting for their turn and the sixth person comes to the bank, then he/she just leaves the bank. Before the customer is being served, the customer needs to enter the account number and each customer will be serviced on first come first served basis.
Use separate Pthreads to create N customers and cashier. Each of these customers as well as the cashier should run as a separate thread. When the customer is being serviced, print the message clearly saying that the customer with account number is being serviced. Assume each customer is done in 5 seconds. You also need to display the waiting list when the customers comes in and when the customer is serviced. You need to display if any customer leaves the bank without getting service (due to the limit of 5 people already waiting). If there is no customer at any time, the cashier just waits for the arrival of customer.
Basically you take an argument from the command line for number of threads = n.
Make an global array of int for the FIFO queue.
Create a cashier thread.
Then in a loop with an arbitrary delay (you can spawn threads) create n customer threads each with a unique id.
The customer threads attempt to get on the queue, if its full they quit out, otherwise they put their id in the array.
The cashier takes the left most id from the queue whenever possible, erases it from the queue and shifts the rest of the values to the left, waits 5 sec, and repeats.
When the cashier finishes with a customer, the customer thread quits.
NOTE: You should have it print out info for each of these steps from all of the threads whenever they happen, plus the state of the queue whenever it changes.
16 freelanceria on tarjonnut keskimäärin 176$ tähän työhön
Hello. I saw your description in carefully. I have an experience in C/ C++ . I can complete for several hours. please give me a chance to work with you. Thank for reading my cover letter.