Download c source code

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)