Download pseudo source code

procedure main:
  shared can_access_count := create_semaphore(1)
  shared count := 0
  shared constant thread_count = read_integer()
  create_threads(thread_count, secondary)
end procedure

procedure secondary:
  // Critical section
  wait(can_access_count)
  count := count + 1
  signal(can_access_count)
end procedure