Question: 1. Implement the Ballroom Dancers simulation based on the Semaphores Example below : Ballroom Dancers Imagine that threads represent ballroom dancers and that two kinds
1. Implement the Ballroom Dancers simulation based on the Semaphores
Example below :
Ballroom Dancers
Imagine that threads represent ballroom dancers and that two kinds of dancers, leaders and followers, wait in two queues before entering the dance floor. When a leader arrives, it checks to see if there is a follower waiting. If so, they can both proceed. Otherwise it waits. Similarly, when a follower arrives, it checks for a leader and either proceeds or waits, accordingly.


Input: ./a.out n m output.txt where n is the number of "leaders" and m is the number of "followers" and output.txt is the output file generated by your program. Output: leader
Solution Here are the variables I used in my solution: Listing 3.17: Queue hint 1 leaders followers0 2 mutex= Semaphore(1) 3 leaderQueue - Semaphore(0) 4 followerlueue - Semaphore(0) 5 rendezvous= Semaphore (0) leaders and follovers are counters that keep track of the number of dancers of each kinds that are waiting. The mutex guarantees exclusive ac- cess to the counters
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
