pthreads/{hello_order_busywait/design/hello_order_busywait.pseudo → position_race/design/position_race.pseudo} RENAMED
@@ -1,20 +1,18 @@
1
  procedure main(argc, argv[])
2
- shared next_thread := 0
 
3
  shared thread_count := integer(argv[1])
4
  for thread_number := 0 to thread_count do
5
  create_thread(greet, thread_number) // thread team
6
  end for
7
  print "Hello from main thread"
8
  end procedure
9
 
10
- procedure greet(thread_number)
11
- // Wait until it is my turn
12
- while next_thread < thread_number do
13
- // busy-wait
14
- end while
15
-
16
- print "Hello from secondary thread", thread_number, " of ", thread_count
17
-
18
- // Allow subsequent thread to do the task
19
- next_thread := next_thread + 1
20
  end procedure
1
  procedure main(argc, argv[])
2
+ shared position := 0
3
+ shared can_access_position := create_mutex()
4
  shared thread_count := integer(argv[1])
5
  for thread_number := 0 to thread_count do
6
  create_thread(greet, thread_number) // thread team
7
  end for
8
  print "Hello from main thread"
9
  end procedure
10
 
11
+ procedure race(thread_number)
12
+ lock(can_access_position)
13
+ position := position + 1
14
+ declare my_position := position
15
+ print "Thread ", thread_number, "/", thread_count ": I arrived at position ",
16
+ my_position
17
+ unlock(can_access_position)
 
 
 
18
  end procedure