Fatal error: Fatal error during lock: Resource deadlock avoided

Indeed. caml_c_thread_register always defaults to registering the given thread in domain 0. This was a pragmatic backwards compatible choice. Until your example, we haven’t had the need for registering C threads with other domains. This needs a little bit of work as we really don’t have a user-programmable handle to domains in the C API.

The interaction of domains with systhreads is described in the OCaml manual.

I’m curious whether your suggested solution of releasing the runtime system around callbacks would work for you or would you prefer having a different API?