Calling Julia functions from a multi-threading scheduler written in C?

I have a scheduler written in C that repetitively executes batches if C functions in multi-threaded fashion:

  • Mutually exclusive groups of C functions update one reactor state (i.e. the total set of C functions is partitioned around a smaller set of reactor states);
  • The C functions are scheduled in and out;
  • Each C function can call into a Julia callback passing it the reactor state.

As a setup my thinking is as follows:

  1. Define a Julia struct holding the reactor state.
  2. The Julia reactor state should have one field holding a reference to a Julia interpreter engine;
  3. In C initialize the Julia reactor state at reactor creation; this includes starting the Julia interpreter engine;
  4. Call reaction callbacks from reactor’s Julia engine.

Is this feasible?

As far as I know, embedding multiple instances of Julia (which uses a compiler, not just an interpreter) within a single process is not supported, and perhaps will never be supported. See this thread from 2014.

The best approach is probably to let Julia “drive” — Julia already has a scheduler for multi-threaded code, so you could spawn Julia threads that call your C functions and pass them callback functions.