@@ -1,11 +1,16 @@
|
|
1 |
shared count := 0
|
|
|
2 |
|
3 |
main:
|
4 |
create_thread(thread_a)
|
5 |
create_thread(thread_b)
|
6 |
|
7 |
thread_a:
|
|
|
8 |
count := count + 1
|
|
|
9 |
|
10 |
thread_b:
|
|
|
11 |
count := count + 1
|
|
1 |
shared count := 0
|
2 |
+
shared mutex := semaphore(1)
|
3 |
|
4 |
main:
|
5 |
create_thread(thread_a)
|
6 |
create_thread(thread_b)
|
7 |
|
8 |
thread_a:
|
9 |
+
wait(mutex)
|
10 |
count := count + 1
|
11 |
+
signal(mutex)
|
12 |
|
13 |
thread_b:
|
14 |
+
wait(mutex)
|
15 |
count := count + 1
|
16 |
+
signal(mutex)
|