Download c source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
main:
	shared thread_count := read_integer()
	shared ready[]
	for index := 0 to thread_count do
		ready[index] := semaphore(not index)
		create_thread(1, secondary, index)

secondary(rank):
	wait(ready[rank])
	statement s1
	signal(ready[(rank + 1) % thread_count])