In my setup, a Julia function calls a C/Rust function play(agent, environment), which spawns some threads, and call functions on agent. agent and environment are Julia objects.
Each of these foreign threads gets registered using jl_adopt_thread, jl_gc_safe_enter, and jl_enter_threaded_region.
During a call to play, the following functions get called in order:
jl_gc_safe_enter- (some computation)
jl_gc_unsafe_enter- (calls a function in
agent) jl_gc_unsafe_leave- (some computation)
jl_gc_safe_leave
Steps 2-6 execute on multiple threads.
According to earlier threads e.g. GC problems with `jl_gc_unsafe_enter` with multithreaded embedding, it seems like calling jl_gc_unsafe_enter while the GC is running leads to segmentation faults. For this reason, what is the best practice for entering a GC-unsafe region? Do I have to call jl_safepoint_wait_gc before jl_gc_unsafe_enter? This function is not exposed in julia.h.