@@ -1,12 +1,15 @@
|
|
1 |
shared count := 0
|
2 |
-
shared
|
3 |
|
4 |
main:
|
|
|
|
|
|
|
5 |
thread_count := read_integer()
|
6 |
create_thread(secondary, thread_count)
|
7 |
|
8 |
secondary:
|
9 |
-
wait(
|
10 |
// Critical section
|
11 |
count := count + 1
|
12 |
-
signal(
|
1 |
shared count := 0
|
2 |
+
shared multiplex
|
3 |
|
4 |
main:
|
5 |
+
upper_limit := read_integer()
|
6 |
+
multiplex := semaphore(upper_limit)
|
7 |
+
|
8 |
thread_count := read_integer()
|
9 |
create_thread(secondary, thread_count)
|
10 |
|
11 |
secondary:
|
12 |
+
wait(multiplex)
|
13 |
// Critical section
|
14 |
count := count + 1
|
15 |
+
signal(multiplex)
|