Skip to content

Commit

Permalink
use SpinLock
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Dec 4, 2020
1 parent 58b0bd2 commit 810479f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ end
@enum WorkerState W_CREATED W_CONNECTED W_TERMINATING W_TERMINATED
mutable struct Worker
id::Int
msg_lock::Threads.ReentrantLock # Lock for del_msgs, add_msgs, and gcflag
msg_lock::Threads.SpinLock # Lock for del_msgs, add_msgs, and gcflag, SpinLock since it needs to be used from finalizers
del_msgs::Array{Any,1}
add_msgs::Array{Any,1}
gcflag::Bool
Expand Down Expand Up @@ -134,7 +134,7 @@ mutable struct Worker
if haskey(map_pid_wrkr, id)
return map_pid_wrkr[id]
end
w=new(id, Threads.ReentrantLock(), [], [], false, W_CREATED, Threads.Condition(), time(), conn_func)
w=new(id, Threads.SpinLock(), [], [], false, W_CREATED, Threads.Condition(), time(), conn_func)
w.initialized = Event()
register_worker(w)
w
Expand Down
15 changes: 7 additions & 8 deletions stdlib/Distributed/src/remotecall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,13 @@ function send_del_client(rr)
elseif id_in_procs(rr.where) # process only if a valid worker
w = worker_from_id(rr.where)
msg = (remoteref_id(rr), myid())
Threads.@spawn begin # Need to spawn task since we can be in finalizer
lock(w.msg_lock) do
push!(w.del_msgs, $msg)
w.gcflag = true
end
lock(any_gc_flag) do
notify(any_gc_flag)
end
# Lock is SpinLock an can thus be acquired from finalizer
lock(w.msg_lock) do
push!(w.del_msgs, msg)
w.gcflag = true
end
lock(any_gc_flag) do
notify(any_gc_flag)
end
end
end
Expand Down

0 comments on commit 810479f

Please sign in to comment.