@@ -1,12 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
main:
|
2 |
while true do
|
3 |
case read_char() of
|
4 |
'H': create_thread(hydrogen)
|
5 |
'O': create_thread(oxygen)
|
6 |
EOF: return
|
7 |
|
8 |
hydrogen:
|
|
|
|
|
9 |
bond()
|
|
|
|
|
10 |
|
11 |
oxygen:
|
|
|
|
|
12 |
bond()
|
|
|
|
1 |
+
shared hydrogen_multiplex := semaphore(2)
|
2 |
+
shared oxygen_multiplex := semaphore(1)
|
3 |
+
shared enter_barrier := barrier(3)
|
4 |
+
shared exit_barrier := barrier(3)
|
5 |
+
|
6 |
main:
|
7 |
while true do
|
8 |
case read_char() of
|
9 |
'H': create_thread(hydrogen)
|
10 |
'O': create_thread(oxygen)
|
11 |
EOF: return
|
12 |
|
13 |
hydrogen:
|
14 |
+
wait(hydrogen_multiplex);
|
15 |
+
wait(enter_barrier);
|
16 |
bond()
|
17 |
+
wait(exit_barrier);
|
18 |
+
signal(hydrogen_multiplex);
|
19 |
|
20 |
oxygen:
|
21 |
+
wait(oxygen_multiplex);
|
22 |
+
wait(enter_barrier);
|
23 |
bond()
|
24 |
+
wait(exit_barrier);
|
25 |
+
signal(oxygen_multiplex);
|