Download c source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
shared count := 0

main:
  thread_count := read_integer()
  upper_limit := read_integer();
  shared multiplex := semaphore(upper_limit)
  create_thread(secondary, thread_count)

secondary:
  wait(multiplex)
  count := count + 1
  signal(multiplex)