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