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 | shared hydrogen_multiplex := semaphore(2)
shared oxygen_multiplex := semaphore(1)
shared enter_barrier := barrier(3)
shared exit_barrier := barrier(3)
main:
while true do
case read_char() of
'H': create_thread(hydrogen)
'O': create_thread(oxygen)
EOF: return
hydrogen:
wait(hydrogen_multiplex);
wait(enter_barrier);
bond()
wait(exit_barrier);
signal(hydrogen_multiplex);
oxygen:
wait(oxygen_multiplex);
wait(enter_barrier);
bond()
wait(exit_barrier);
signal(oxygen_multiplex);
|