Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/atexit tests #37

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions test/atexit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,29 +202,25 @@ 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)
""" => 11,
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 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.
Expand All @@ -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,
Expand Down
Loading