mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-05-01 01:04:43 +00:00
This test case is based off Sebastian Godelet's work, which found a bug that
can occur when release/3 is called on a barrier and then other calls to
wait/3 are made. The final call to wait/3 tries to execute the normal
'unblock the barrier' code and deadlocks there because the barrier is
already unlocked, specifically a value is already present in the "Go" mvar.
Thanks Sebastian for your test case.
library/thread.barrier.m:
Handle release/3 properly: release/3 now sets the number of remaining
threads to reach the barrier to zero, and wait/3 will determine why this
iz zero (it's normally at least one), and if it is because release was
called then no error is raised. The other reasion why the number of
remaining threads may be zero is because wait has been called too many
times, in this case wait/3 will throw an exception.
tests/hard_coded/Mmakefile:
tests/hard_coded/thread_barrier_test.exp:
tests/hard_coded/thread_barrier_test.m:
Add new test case.
tests/hard_coded/thread_test_utils.m
This module contains code that may be useful for other concurrency
tests.
66 lines
1.3 KiB
Plaintext
66 lines
1.3 KiB
Plaintext
Test spawn and wait
|
|
Messages from thread 0:
|
|
-- testing spawning with 5 threads
|
|
spawning thread #1
|
|
spawning thread #2
|
|
spawning thread #3
|
|
spawning thread #4
|
|
spawning thread #5
|
|
-- test finished
|
|
Messages from thread 1:
|
|
thread 1 starting
|
|
fib(10) = 89
|
|
thread 1 exiting
|
|
Messages from thread 2:
|
|
thread 2 starting
|
|
fib(15) = 987
|
|
thread 2 exiting
|
|
Messages from thread 3:
|
|
thread 3 starting
|
|
fib(20) = 10946
|
|
thread 3 exiting
|
|
Messages from thread 4:
|
|
thread 4 starting
|
|
fib(25) = 121393
|
|
thread 4 exiting
|
|
Messages from thread 5:
|
|
thread 5 starting
|
|
fib(30) = 1346269
|
|
thread 5 exiting
|
|
|
|
Test release
|
|
Messages from thread 0:
|
|
-- testing barrier release at 3 of 5
|
|
spawning thread #1
|
|
spawning thread #2
|
|
spawning thread #3
|
|
spawning thread #4
|
|
spawning thread #5
|
|
waiting: before release
|
|
done waiting, test finished: after release
|
|
Messages from thread 1:
|
|
thread starting
|
|
fib(10) = 89
|
|
waiting: before release
|
|
done waiting: after release
|
|
Messages from thread 2:
|
|
thread starting
|
|
fib(15) = 987
|
|
waiting: before release
|
|
done waiting: after release
|
|
Messages from thread 3:
|
|
thread starting
|
|
fib(20) = 10946
|
|
releasing barrier
|
|
released.
|
|
Messages from thread 4:
|
|
thread starting
|
|
fib(25) = 121393
|
|
waiting: after release
|
|
done waiting: after release
|
|
Messages from thread 5:
|
|
thread starting
|
|
fib(30) = 1346269
|
|
waiting: after release
|
|
done waiting: after release
|