Skip to content

Commit

Permalink
fixup! Make worker state variable threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWrigley committed Jun 2, 2024
1 parent ec8bce0 commit f4576aa
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ isfailed(rr) = fetch_from_owner(istaskfailed, rr)
ws = ts = product(1:2, 1:2)
@testset "from worker $w1 to $w2 via 1" for (w1, w2) in ws
@testset "from thread $w1.$t1 to $w2.$t2" for (t1, t2) in ts
# We want (the default) lazyness, so that we wait for `Worker.c_state`!
# We want (the default) laziness, so that we wait for `Worker.c_state`!
procs_added = addprocs(2; exeflags, lazy=true)
@everywhere procs_added using Base.Threads

Expand All @@ -44,11 +44,12 @@ isfailed(rr) = fetch_from_owner(istaskfailed, rr)
take!(chan)
end

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

# Check the tasks
@test isdone(send)
Expand Down

0 comments on commit f4576aa

Please sign in to comment.