main:
shared male_queue := semaphore(0)
shared female_queue := semaphore(0)
shared male_enter := semaphore(1)
shared female_enter := semaphore(1)
shared male_exit := semaphore(0)
shared female_exit := semaphore(0)
while true do
case read_char() of
'M': create_thread(male)
'W': create_thread(female)
EOF: return
male:
signal(male_queue)
wait(female_queue)
wait(male_enter)
dance()
signal(male_exit)
wait(female_exit)
signal(male_enter)
female:
signal(female_queue)
wait(male_queue)
wait(female_enter)
dance()
signal(female_exit)
wait(male_exit)
signal(female_enter)