|
@@ -1,20 +1,18 @@
|
|
| 1 |
procedure main(argc, argv[])
|
| 2 |
-
shared
|
|
|
|
| 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
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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
|