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

run finalizers on their own thread #35689

Open
JeffBezanson opened this issue May 1, 2020 · 4 comments
Open

run finalizers on their own thread #35689

JeffBezanson opened this issue May 1, 2020 · 4 comments
Labels
GC Garbage collector multithreading Base.Threads and related functionality

Comments

@JeffBezanson
Copy link
Sponsor Member

In general, finalizers may need to acquire locks, so they should be guaranteed to run on a separate thread to avoid conflicts with the main execution threads. @vtjnash may be able to provide some more details.

@JeffBezanson JeffBezanson added multithreading Base.Threads and related functionality GC Garbage collector labels May 1, 2020
@maleadt
Copy link
Member

maleadt commented May 2, 2020

Had to work around that recently, by disabling finalizers when taking a lock that might also be taken during finalizers: JuliaGPU/CuArrays.jl@2258a24

@vtjnash
Copy link
Sponsor Member

vtjnash commented May 3, 2020

Relatedly, I think we should consider renaming jl_gc_enable_finalizers, change the design (#11207), and/or eventually remove this. This function name misleadingly sounds like it prevents finalizers from being run concurrently with a particular region of code. Indeed, the implementation further seems to imply that too. However, with threading, it's not actually true. We could make it true, but I think it's better just to change this to jl_gc_exclude_finalizers_on_thread (after this issue is closed, it'd become a no-op).

@OkonSamuel
Copy link
Contributor

@vtjnash . It would be nice to have the option of preventing finalizers from running concunrently.
That would solve the annoying error in running finalizer: ErrorException("concurrency violation detected") silent warning am getting at MLJ

@mkitti
Copy link
Contributor

mkitti commented Feb 3, 2023

Following the test-test-set pattern in the manual helped seems to help resolve an issue we had with HDF5.jl when working with finalizers and locks:
JuliaIO/HDF5.jl#1048

https://docs.julialang.org/en/v1/manual/multi-threading/#Safe-use-of-Finalizers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GC Garbage collector multithreading Base.Threads and related functionality
Projects
None yet
Development

No branches or pull requests

5 participants