Skip to content

Commit 3164bd0

Browse files
authored
fix finalizer task switch (#54)
1 parent ad20954 commit 3164bd0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/datastore.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ end
9292
# HACK: Force remote GC messages to be executed serially
9393
const SEND_QUEUE = Channel(typemax(Int))
9494
const SEND_TASK = Ref{Task}()
95-
function _enqueue_work(f, args...)
95+
function _enqueue_work(f, args...; gc_context=false)
9696
if !isassigned(SEND_TASK)
9797
SEND_TASK[] = @async begin
9898
while true
@@ -108,7 +108,20 @@ function _enqueue_work(f, args...)
108108
end
109109
end
110110
end
111-
put!(SEND_QUEUE, (f, args))
111+
if gc_context
112+
while true
113+
if trylock(SEND_QUEUE)
114+
try
115+
put!(SEND_QUEUE, (f, args))
116+
break
117+
finally
118+
unlock(SEND_QUEUE)
119+
end
120+
end
121+
end
122+
else
123+
put!(SEND_QUEUE, (f, args))
124+
end
112125
end
113126

114127
function poolref(d::DRef, recv=false)
@@ -149,7 +162,7 @@ function poolunref(d::DRef, to_pid=0)
149162
transfers = get(send_datastore_counter, (d.owner,d.id), Dict{Int,Atomic{Int}}())
150163
delete!(send_datastore_counter, (d.owner,d.id))
151164
# Tell the owner we hold no more references
152-
_enqueue_work(remotecall_wait, poolunref_owner, d.owner, d.id, transfers)
165+
_enqueue_work(remotecall_wait, poolunref_owner, d.owner, d.id, transfers; gc_context=true)
153166
end
154167
end
155168
end

0 commit comments

Comments
 (0)