File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -1337,19 +1337,34 @@ end
13371337
13381338using Random: randstring
13391339
1340+ # Exit handler state
1341+ const shutting_down = Threads. Atomic {Bool} (false )
1342+
1343+ function atexit_handler ()
1344+ if inited[]
1345+ terminate_all_workers ()
1346+ end
1347+
1348+ shutting_down[] = true
1349+ @lock any_gc_flag notify (any_gc_flag)
1350+ if ! isnothing (gc_msgs_task)
1351+ wait (gc_msgs_task)
1352+ end
1353+ end
1354+
13401355# do initialization that's only needed when there is more than 1 processor
13411356const inited = Threads. Atomic {Bool} (false )
13421357function init_multi ()
13431358 if ! Threads. atomic_cas! (inited, false , true )
13441359 push! (Base. package_callbacks, _require_callback)
1345- atexit (terminate_all_workers)
13461360 init_bind_addr ()
13471361 cluster_cookie (randstring (HDR_COOKIE_LEN))
13481362 end
13491363 return nothing
13501364end
13511365
13521366function init_parallel ()
1367+ atexit (atexit_handler)
13531368 start_gc_msgs_task ()
13541369
13551370 # start in "head node" mode, if worker, will override later.
Original file line number Diff line number Diff line change @@ -272,10 +272,12 @@ end
272272# XXX : Is this worth the additional complexity?
273273# `flush_gc_msgs` has to iterate over all connected workers.
274274const any_gc_flag = Threads. Condition ()
275+ gc_msgs_task:: Union{Task, Nothing} = nothing
276+
275277function start_gc_msgs_task ()
276- errormonitor (
278+ global gc_msgs_task = errormonitor (
277279 @async begin
278- while true
280+ while ! shutting_down[]
279281 lock (any_gc_flag) do
280282 # this might miss events
281283 wait (any_gc_flag)
You can’t perform that action at this time.
0 commit comments