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.

1. Implement the Ballroom Dancers simulation based on the Semaphores Example below: Ballroom Dancers Imagine that threads represent ballroom dancers and that two

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 dances with follower for all threads... Note, the number of leaders and followers may be different. We want to make sure all dancers dance at least once. After all have dance, the program ends. Hint: keep a running count of how many followers have danced and leaders have danced. Name your program: dance.cpp and place it in your pgm directory. If a binary semaphore is required, use a posix mutex instead.

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!