@@ -1,16 +1,29 @@
|
|
1 |
procedure main()
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
4 |
'H': create_thread(hydrogen)
|
5 |
'O': create_thread(oxygen)
|
|
|
6 |
end case
|
7 |
end while
|
8 |
end procedure
|
9 |
|
10 |
procedure hydrogen()
|
|
|
|
|
11 |
bond()
|
|
|
|
|
12 |
end procedure
|
13 |
|
14 |
procedure oxygen()
|
|
|
|
|
15 |
bond()
|
|
|
|
|
16 |
end procedure
|
1 |
procedure main()
|
2 |
+
shared hydrogen_multiplex := create_semaphore(2)
|
3 |
+
shared oxygen_multiplex := create_semaphore(1)
|
4 |
+
shared device_barrier := crate_barrier(3)
|
5 |
+
|
6 |
+
while true do
|
7 |
+
case read_char() of
|
8 |
'H': create_thread(hydrogen)
|
9 |
'O': create_thread(oxygen)
|
10 |
+
EOF: return
|
11 |
end case
|
12 |
end while
|
13 |
end procedure
|
14 |
|
15 |
procedure hydrogen()
|
16 |
+
wait(hydrogen_multiplex)
|
17 |
+
wait(device_barrier)
|
18 |
bond()
|
19 |
+
wait(device_barrier)
|
20 |
+
signal(hydrogen_multiplex)
|
21 |
end procedure
|
22 |
|
23 |
procedure oxygen()
|
24 |
+
wait(oxygen_multiplex)
|
25 |
+
wait(device_barrier)
|
26 |
bond()
|
27 |
+
wait(device_barrier)
|
28 |
+
signal(oxygen_multiplex)
|
29 |
end procedure
|