Whale Mating Help

I could use some help/hints for the whale mating problem. I assume that semaphores or cv’s are the best primitives to use for the solution. But other than that I’m at a lost. I’ve tried looking at the tests to get some guidance but I can’t come up with anything. I’m really just looking for a place to start. Sorry if this question isn’t appropriate for the forum.

Whalemating is a coordination and signaling problem. You might approach this by thinking about what should happen in a few cases:

  • Imagine that all of the males have started as have all the females. But no matchmakers are present yet. What should happen?
  • Now imagine that one matchmaker is started. What should happen now? How do the other threads know when the matchmaker arrives? Clearly they need to wait it some way—but how?
  • Now permute the roles and think about it again: i.e., imagine that all of the males and matchmakers have been created but no females, etc. Obviously a good solution needs to work in all three cases.

Come by office hours for more detailed help.