1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 | barrier:
return record of
count := 0
mutex := semaphore(1)
turnstile1 := semaphore(0)
turnstile2 := semaphore(1)
wait(barrier):
barrier_phase1(barrier)
barrier_phase2(barrier)
barrier_phase1(barrier):
wait(mutex)
if ++count == thread_count then
wait(turnstile2)
signal(turnstile1)
signal(mutex)
wait(turnstile1)
signal(turnstile1)
barrier_phase2(barrier):
wait(mutex)
if --count == 0 then
wait(turnstile1)
signal(turnstile2)
signal(mutex)
wait(turnstile2)
signal(turnstile2)
main:
shared thread_count := read_integer()
shared my_barrier := barrier(thread_count)
create_thread(secondary, thread_count)
secondary:
while true do
Sentence A
barrier_phase1(my_barrier)
Sentence B
barrier_phase2(my_barrier)
third:
for row := 0 to row_count do
process_row()
wait(mybarrier)
|