Sem_post(accessSeats) // release the mutex on the chair Sem_post(Barber) // bring customer for haircut Sem_wait(accessSeats) // mutex to protect the number of available seats Sem_wait(Customers) // waits for a customer (sleeps) (although the actual code is in C, I wrote anycodings_algorithm the following pseudo-code without much care anycodings_algorithm for the syntax for sake of anycodings_algorithm problem-understading, only using sem_wait anycodings_algorithm and sem_post1 for smoother reading) Semaphore Customers = 0 I have made a implementation of this using anycodings_algorithm the following basic-idea When another anycodings_algorithm customer arrives, he then must wake up the anycodings_algorithm barber. If, anycodings_algorithm then, there is no one in the waiting room, anycodings_algorithm the barber goes to sleep. If there is anycodings_algorithm someone, he cuts his hair (symbolizing some anycodings_algorithm processing) and the costumer leaves. It's based on the premise that a barber (a anycodings_algorithm thread) sleeps when there are no customers anycodings_algorithm (each customer is a thread) in the waiting anycodings_algorithm room (which is a semaphore). The Sleeping Barber Problem is a classical anycodings_algorithm synchronization problem that many of you may anycodings_algorithm be familiar with or at least heard of.
0 Comments
Leave a Reply. |