Download pseudo source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
procedure main(argc, argv[])
  shared position := 0
  shared can_access_position := create_mutex()
  shared thread_count := integer(argv[1])
  for thread_number := 0 to thread_count do
    create_thread(greet, thread_number) // thread team
  end for
  print "Hello from main thread"
end procedure

procedure race(thread_number)
  lock(can_access_position)
  position := position + 1
  declare my_position := position
  print "Thread ", thread_number, "/", thread_count ": I arrived at position ",
    my_position
  unlock(can_access_position)
end procedure