Download pseudo source code

procedure main(argc, argv[])
  shared next_thread := 0
  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 greet(thread_number)
  // Wait until it is my turn
  while next_thread < thread_number do
    // busy-wait
  end while

  print "Hello from secondary thread", thread_number, " of ", thread_count

  // Allow subsequent thread to do the task
  next_thread := next_thread + 1
end procedure