Question: Problem given in a previous exam: Students decide to meet and go watch a movie. Students decide to meet and go watch a movie. decide
Problem given in a previous exam: Students decide to meet and go watch a movie. Students decide to meet and go watch a movie. decide to meet and go watch a movie. After they gather together After they gather together gather together in groups of in groups of in groups of group_size group_size group_size, they go buy tickets. Each , they go buy tickets. Each , they go buy tickets. Each student student student buys his own ticket (becomes a customer). There are two ticket- ticket-booths (each booth has on booths (each booth has on booths (each booth has one clerk). If the clerk is available it will serve the next customer on line (one customer at a time). There is only one line time). There is only one line only one line for both booths. for both booths. for both booths. Using semaphores and operations on semaphores, synchronize the two thread types: Student and Clerk. There are numStundents (default 9) and numClerks (default 2). Consider that there are no customers on line at the booth in the early morning. From the clerks point of view (it is up to you) you can consider that both clerks were already at work or that neither of them has arrived yet (when the first customer showed up). There are more customers than numStudents. Give the type, initial value of each semaphore used, and shortly explain its use. Dont use Boolean variables if their use can be replaced by semaphores. Roughly before the synchronization, a possible execution pseudo-code for the threads might be:
Student ( ) { Clerk ( ) {get to workplace //napping
{ arrive to meeting place // napping while(true) {serve customer // if a customer} }
group together
go buy tickets
buy ticket //napping
watch movie // napping } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
