diff --git a/test/atexit.jl b/test/atexit.jl index 5b4fbc0b44a40..4a37d465f250b 100644 --- a/test/atexit.jl +++ b/test/atexit.jl @@ -202,15 +202,11 @@ using Test # This will run in a concurrent task, testing that we can register atexit # hooks from another task while running atexit hooks. Threads.@spawn begin - Core.println("INSIDE") take!(c) # block on c - Core.println("go") atexit() do - Core.println("exit11") exit(11) end take!(c) # keep the _atexit() loop alive until we've added another item. - Core.println("done") end end exit(0) @@ -218,13 +214,13 @@ using Test # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # 3. attempting to register a hook after all hooks have finished (disallowed) """ - const atexit_has_finished = Threads.Atomic{Bool}(false) + const atexit_has_finished = Threads.Atomic{Int}(0) atexit() do Threads.@spawn begin # Block until the atexit hooks have all finished. We use a manual "spin # lock" because task switch is disallowed inside the finalizer, below. - while !atexit_has_finished[] end - Core.println("done") + atexit_has_finished[] = 1 + while atexit_has_finished[] == 1 end try # By the time this runs, all the atexit hooks will be done. # So this will throw. @@ -236,18 +232,16 @@ using Test exit(22) end end + while atexit_has_finished[] == 0 end end # Finalizers run after the atexit hooks, so this blocks exit until the spawned # task above gets a chance to run. x = [] finalizer(x) do x - Core.println("FINALIZER") # Allow the spawned task to finish - atexit_has_finished[] = true - Core.println("ready") + atexit_has_finished[] = 2 # Then spin forever to prevent exit. - while atexit_has_finished[] end - Core.println("exiting") + while atexit_has_finished[] == 2 end end exit(0) """ => 22,