|
@@ -1,19 +1,28 @@
|
|
| 1 |
procedure main()
|
| 2 |
// How many threads have arrived to the barrier
|
| 3 |
shared count := 0
|
| 4 |
// Protects the increment of the count
|
| 5 |
shared can_access_count := create_semaphore(1)
|
| 6 |
// Locked (0) until all threads arrive, then it is unlocked (1)
|
| 7 |
shared barrier := create_semaphore(0)
|
| 8 |
// Read thread count from standard input
|
| 9 |
input shared const thread_count
|
| 10 |
// Create a thread team running secondary
|
| 11 |
create_threads(thread_count, secondary)
|
| 12 |
end procedure
|
| 13 |
|
| 14 |
procedure secondary()
|
| 15 |
Statement A
|
| 16 |
// Adapt rendezvous solution here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
// Statement B can be only executed until all threads have run Statement A
|
| 18 |
Statement B
|
| 19 |
end procedure
|
| 1 |
procedure main()
|
| 2 |
// How many threads have arrived to the barrier
|
| 3 |
shared count := 0
|
| 4 |
// Protects the increment of the count
|
| 5 |
shared can_access_count := create_semaphore(1)
|
| 6 |
// Locked (0) until all threads arrive, then it is unlocked (1)
|
| 7 |
shared barrier := create_semaphore(0)
|
| 8 |
// Read thread count from standard input
|
| 9 |
input shared const thread_count
|
| 10 |
// Create a thread team running secondary
|
| 11 |
create_threads(thread_count, secondary)
|
| 12 |
end procedure
|
| 13 |
|
| 14 |
procedure secondary()
|
| 15 |
Statement A
|
| 16 |
// Adapt rendezvous solution here
|
| 17 |
+
wait(can_access_count)
|
| 18 |
+
count := count + 1
|
| 19 |
+
if count = thread_count then
|
| 20 |
+
for index := 0 to thread_count do
|
| 21 |
+
signal(barrier)
|
| 22 |
+
end for
|
| 23 |
+
end if
|
| 24 |
+
signal(can_access_count)
|
| 25 |
+
wait(barrier)
|
| 26 |
// Statement B can be only executed until all threads have run Statement A
|
| 27 |
Statement B
|
| 28 |
end procedure
|