9292# HACK: Force remote GC messages to be executed serially
9393const SEND_QUEUE = Channel (typemax (Int))
9494const 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
112125end
113126
114127function 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
155168end
0 commit comments