I have been investigating how C library wrappers can achieve non-blocking I/O in OCaml. Here’s an example of such a wrapper (stub): postgresql-ocaml/src/postgresql_stubs.c at c14d830d3eacd36c18ecf8d2bb93d3b92e092539 · mmottl/postgresql-ocaml · GitHub
caml_enter_blocking_section();
res =
(nparams == 0 && !binary_result)
? PQexec(conn, query)
: PQexecParams(
conn, query, nparams, param_types,
params, lengths, formats, binary_result);
if (param_types != NULL) caml_stat_free(param_types);
free_binary_params(formats, lengths);
free_params(params, nparams);
caml_stat_free(query);
caml_leave_blocking_section();
According to OCaml - Interfacing C with OCaml -
caml_enter_blocking_section
as an alias forcaml_release_runtime_system
And -
caml_release_runtime_system()
The calling thread releases the domain lock and other OCaml resources, enabling other threads to run OCaml code in parallel with the execution of the calling thread.
So this is specifically when using systhreads.
But what about when using fibers created with effect libraries like Eio? Do these interact in the same way with the runtime system? In other words, does calling caml_release_runtime_system()
yield the current fiber and allow another fiber to run?