Skip to content

Commit 877be4f

Browse files
committed
Improve worker launch thread-safety
The `launched_q` array is filled concurrently by the launcher tasks for each worker. Now it's wrapped inside `Base.Lockable` for thread-safety.
1 parent 91fe613 commit 877be4f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/cluster.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ function addprocs_locked(manager::ClusterManager; kwargs...)
475475

476476
# References to launched workers, filled when each worker is fully initialized and
477477
# has connected to all nodes.
478-
launched_q = Int[] # Asynchronously filled by the launch method
478+
launched_q = Base.Lockable(Int[]) # Asynchronously filled by the launch method
479479

480480
# The `launch` method should add an object of type WorkerConfig for every
481481
# worker launched. It provides information required on how to connect
@@ -522,7 +522,7 @@ function addprocs_locked(manager::ClusterManager; kwargs...)
522522
remote_do(set_valid_processes, pid, all_w)
523523
end
524524

525-
sort!(launched_q)
525+
sort!(@lock launched_q launched_q[])
526526
end
527527

528528
function set_valid_processes(plist::Array{Int})
@@ -551,7 +551,7 @@ default_addprocs_params() = Dict{Symbol,Any}(
551551

552552
function setup_launched_worker(manager, wconfig, launched_q)
553553
pid = create_worker(manager, wconfig)
554-
push!(launched_q, pid)
554+
@lock launched_q push!(launched_q[], pid)
555555

556556
# When starting workers on remote multi-core hosts, `launch` can (optionally) start only one
557557
# process on the remote machine, with a request to start additional workers of the
@@ -589,7 +589,7 @@ function launch_n_additional_processes(manager, frompid, fromconfig, cnt, launch
589589
Threads.@spawn Threads.threadpool() begin
590590
pid = create_worker(manager, wconfig)
591591
remote_do(redirect_output_from_additional_worker, frompid, pid, port)
592-
push!(launched_q, pid)
592+
@lock launched_q push!(launched_q[], pid)
593593
end
594594
end
595595
end

0 commit comments

Comments
 (0)