Download pseudo source code

procedure main()
  shared can_access_count := create_semaphore(1)
  shared count := 0
  create_thread(thread_a)
  create_thread(thread_b)
end procedure

procedure thread_a()
  wait(can_access_count)
  count := count + 1
  signal(can_access_count)
end procedure

procedure thread_b()
  wait(can_access_count)
  count := count + 1
  signal(can_access_count)
end procedure