Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

race conditions in finalizers #694

Open
cmcaine opened this issue Sep 6, 2023 · 1 comment
Open

race conditions in finalizers #694

cmcaine opened this issue Sep 6, 2023 · 1 comment

Comments

@cmcaine
Copy link

cmcaine commented Sep 6, 2023

Hello,

finalizer functions in Julia can interrupt any other code, including other finalizers, which means that any access to shared state must be guarded by some kind of synchronization strategy.

Currently, the finalizers for various GObjects access several bits of shared state without any synchronization and this permits race-conditions, unless there is something quite clever going on that I didn't see.

Here's an unsafe finalizer, delref from gtype.jl (not the only one). Note that it accesses several globals without using atomic operations or locks:

https://github.com/JuliaGraphics/Gtk.jl/blob/881fdce8eb5a8bce2f1a846f79ac7142177e5b2a/src/GLib/gtype.jl#L405C1-L422

The segfault reported in #684 is possibly related.

I found this bug because I was reviewing the advice given in the manual for writing safe finalizers.
You can find a discussion of various strategies in that PR: JuliaLang/julia#51191

@tknopp
Copy link
Collaborator

tknopp commented Sep 7, 2023

could you please also file an issue at https://github.com/JuliaGtk/Gtk4.jl if that is an issue there as well. Gtk.jl is not maintained anymore. Future development happens within Gtk4.jl

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants