Skip to content

Commit

Permalink
Create workers only once in the thread-safety tests
Browse files Browse the repository at this point in the history
This cuts the running time down from ~1m to ~10s. It shouldn't be necessary to
re-create the workers for every iteration of the inner loop.
  • Loading branch information
JamesWrigley authored and IanButterworth committed Jan 26, 2025
1 parent 614f4c8 commit 8494bbd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test/threads.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Test
using Distributed, Base.Threads
using Distributed
using Base.Iterators: product

exeflags = ("--startup-file=no",
Expand All @@ -12,7 +12,7 @@ function call_on(f, wid, tid)
t = Task(f)
ccall(:jl_set_task_tid, Cvoid, (Any, Cint), t, tid - 1)
schedule(t)
@assert threadid(t) == tid
@assert Threads.threadid(t) == tid
t
end
end
Expand All @@ -27,12 +27,12 @@ isfailed(rr) = fetch_from_owner(istaskfailed, rr)

@testset "RemoteChannel allows put!/take! from thread other than 1" begin
ws = ts = product(1:2, 1:2)

# We want (the default) laziness, so that we wait for `Worker.c_state`!
procs_added = addprocs(2; exeflags, lazy=true)

@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) laziness, so that we wait for `Worker.c_state`!
procs_added = addprocs(2; exeflags, lazy=true)
@everywhere procs_added using Base.Threads

p1 = procs_added[w1]
p2 = procs_added[w2]
chan_id = first(procs_added)
Expand All @@ -57,8 +57,8 @@ isfailed(rr) = fetch_from_owner(istaskfailed, rr)

@test !isfailed(send)
@test !isfailed(recv)

rmprocs(procs_added)
end
end

rmprocs(procs_added)
end

0 comments on commit 8494bbd

Please sign in to comment.