1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)