From 9877c30e29dc869d8027e5704d0debc44311488a Mon Sep 17 00:00:00 2001 From: Jonas Schulze Date: Tue, 27 Oct 2020 17:50:48 +0100 Subject: [PATCH 1/2] Make any_gc_flag threadsafe --- stdlib/Distributed/src/remotecall.jl | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/stdlib/Distributed/src/remotecall.jl b/stdlib/Distributed/src/remotecall.jl index f4845221a611a..675edf55e5030 100644 --- a/stdlib/Distributed/src/remotecall.jl +++ b/stdlib/Distributed/src/remotecall.jl @@ -247,11 +247,14 @@ function del_clients(pairs::Vector) end end -const any_gc_flag = Condition() +const any_gc_flag = Threads.Condition() function start_gc_msgs_task() - @async while true - wait(any_gc_flag) - flush_gc_msgs() + @async begin + lock(any_gc_flag) + while true + wait(any_gc_flag) + flush_gc_msgs() + end end end @@ -262,7 +265,12 @@ function send_del_client(rr) w = worker_from_id(rr.where) push!(w.del_msgs, (remoteref_id(rr), myid())) w.gcflag = true - notify(any_gc_flag) + lock(any_gc_flag) + try + notify(any_gc_flag) + finally + unlock(any_gc_flag) + end end end @@ -290,7 +298,12 @@ function send_add_client(rr::AbstractRemoteRef, i) w = worker_from_id(rr.where) push!(w.add_msgs, (remoteref_id(rr), i)) w.gcflag = true - notify(any_gc_flag) + lock(any_gc_flag) + try + notify(any_gc_flag) + finally + unlock(any_gc_flag) + end end end From 179ac64638bcd8558796cb311943df5383d706f3 Mon Sep 17 00:00:00 2001 From: Jonas Schulze Date: Tue, 27 Oct 2020 21:09:34 +0100 Subject: [PATCH 2/2] Idiomatic usage of Condition --- stdlib/Distributed/src/remotecall.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stdlib/Distributed/src/remotecall.jl b/stdlib/Distributed/src/remotecall.jl index 675edf55e5030..95948e91d2c3c 100644 --- a/stdlib/Distributed/src/remotecall.jl +++ b/stdlib/Distributed/src/remotecall.jl @@ -251,9 +251,13 @@ const any_gc_flag = Threads.Condition() function start_gc_msgs_task() @async begin lock(any_gc_flag) - while true - wait(any_gc_flag) - flush_gc_msgs() + try + while true + wait(any_gc_flag) + flush_gc_msgs() + end + finally + unlock(any_gc_flag) end end end