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

GC-safe ccalls #51574

Open
kpamnany opened this issue Oct 3, 2023 · 1 comment
Open

GC-safe ccalls #51574

kpamnany opened this issue Oct 3, 2023 · 1 comment
Labels
GC Garbage collector multithreading Base.Threads and related functionality

Comments

@kpamnany
Copy link
Contributor

kpamnany commented Oct 3, 2023

It is sometimes the case that a call to an external C library can take a long time; solvers are a good example. We've observed such a call taking tens of minutes, and while that was happening, another Julia thread triggered GC. At this point, all threads stop, except for the thread running the solver call and the program froze until the ccall returned, many minutes later.

If you know that the call to the external library does not manipulate Julia memory, then you can ccall jl_gc_safe_enter and jl_gc_safe_leave before and after the external call.

So:

  1. Is there another solution to this problem?
  2. If not, why is this solution not defined in Base.GC (like GC.safepoint) and documented?
  3. Does it make sense to add a parameter to ccall that allows for it to be a GC safe region automatically?
@kpamnany kpamnany added GC Garbage collector multithreading Base.Threads and related functionality labels Oct 3, 2023
@vchuravy
Copy link
Member

vchuravy commented Oct 3, 2023

This should be addressed by #49933

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

2 participants