1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
main:
shared male_queue := semaphore(0)
shared female_queue := semaphore(0)
while true:
case read_char() of:
'M': create_thread(male)
'W': create_thread(female)
EOF: return
male:
signal(female_queue)
wait(male_queue)
dance()
female:
signal(male_queue)
wait(female_queue)
dance()