From f3260c9267997433d164ad1585229afc051b9dfc Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Mon, 5 Jun 2023 11:18:44 -0600 Subject: [PATCH 1/2] Remove printlns from test/atexit.jl (#50066) --- test/atexit.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/atexit.jl b/test/atexit.jl index 5b4fbc0b44a40..64b56e32466df 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) @@ -224,7 +220,6 @@ using Test # 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") try # By the time this runs, all the atexit hooks will be done. # So this will throw. @@ -241,13 +236,10 @@ using Test # 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") # Then spin forever to prevent exit. while atexit_has_finished[] end - Core.println("exiting") end exit(0) """ => 22, From 8edc87246f495c94cf31762deb07061dbb2d25d6 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 14 Nov 2023 20:53:17 +0000 Subject: [PATCH 2/2] test: fix race in atexit test Exposed by the presence of any atexit hooks in the new process, such as added in this PR. --- test/atexit.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/atexit.jl b/test/atexit.jl index 64b56e32466df..4a37d465f250b 100644 --- a/test/atexit.jl +++ b/test/atexit.jl @@ -214,12 +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 + 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. @@ -231,15 +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 # Allow the spawned task to finish - atexit_has_finished[] = true + atexit_has_finished[] = 2 # Then spin forever to prevent exit. - while atexit_has_finished[] end + while atexit_has_finished[] == 2 end end exit(0) """ => 22,