Skip to content

Commit f4576aa

Browse files
committed
fixup! Make worker state variable threadsafe
1 parent ec8bce0 commit f4576aa

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test/threads.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ isfailed(rr) = fetch_from_owner(istaskfailed, rr)
2929
ws = ts = product(1:2, 1:2)
3030
@testset "from worker $w1 to $w2 via 1" for (w1, w2) in ws
3131
@testset "from thread $w1.$t1 to $w2.$t2" for (t1, t2) in ts
32-
# We want (the default) lazyness, so that we wait for `Worker.c_state`!
32+
# We want (the default) laziness, so that we wait for `Worker.c_state`!
3333
procs_added = addprocs(2; exeflags, lazy=true)
3434
@everywhere procs_added using Base.Threads
3535

@@ -44,11 +44,12 @@ isfailed(rr) = fetch_from_owner(istaskfailed, rr)
4444
take!(chan)
4545
end
4646

47-
# Wait on the spawned tasks on the owner
48-
@sync begin
49-
Threads.@spawn fetch_from_owner(wait, recv)
50-
Threads.@spawn fetch_from_owner(wait, send)
51-
end
47+
# Wait on the spawned tasks on the owner. Note that we use
48+
# timedwait() instead of @sync to avoid deadlocks.
49+
t1 = Threads.@spawn fetch_from_owner(wait, recv)
50+
t2 = Threads.@spawn fetch_from_owner(wait, send)
51+
@test timedwait(() -> istaskdone(t1), 5) == :ok
52+
@test timedwait(() -> istaskdone(t2), 5) == :ok
5253

5354
# Check the tasks
5455
@test isdone(send)

0 commit comments

Comments
 (0)