Skip to content

GC-safe ccalls #51574

@kpamnany

Description

@kpamnany

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    GCGarbage collectormultithreadingBase.Threads and related functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions