1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 | 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)
|