1
2
3
4
5
6
7
8
9
10
11
12
shared count := 0
shared mutex := semaphore(1)
main:
thread_count := read_integer()
create_thread(secondary, thread_count)
secondary:
wait(mutex)
// Critical section
count := count + 1
signal(mutex)
1
2
3
4
5
6
7
8
9
10
11
12
shared count := 0
shared mutex := semaphore(1)
main:
thread_count := read_integer()
create_thread(secondary, thread_count)
secondary:
wait(mutex)
// Critical section
count := count + 1
signal(mutex)