@Jonathan pointed me out that
caml_c_thread_register() should be called if some C threads other than the main one call OCaml functions (OCaml - Interfacing C with OCaml, quoted in Using an OCaml library from multithreaded Python code · Issue #76 · thierry-martinez/pyml · GitHub).
Callbacks from C to OCaml are possible only if the calling thread is known to the OCaml run-time system. Threads created from OCaml (through the Thread.create function of the system threads library) are automatically known to the run-time system. If the application creates additional threads from C and wishes to callback into OCaml code from these threads, it must first register them with the run-time system. The following functions are declared in the include file <caml/threads.h>.: [caml_c_thread_register() and caml_c_thread_unregister()].
If I understand correctly, these functions are declared in
systhreads: is it safe to suppose that if we don’t link (nor use)
threads.cmxa, we don’t need to care about registering C threads (assuming that we don’t call several functions in parallel: in the case of @Jonathan, it is guaranteed by the Python GIL)?
(I suspect that this is the kind of things that will change with OCaml 5: in the case that it is safe to ignore
caml_c_thread_register if we do not use thread in OCaml <=4.14, I would be interested to know if it remains true with OCaml 5 if the OCaml program is known to be single core.)