I’m testing a specific case of Embedding Julia · The Julia Language on MacOS.
I need to call Julia from a dylib (dylib code in C++) that is called from Julia to pass input data and analyze the results.
In other words:
- from Julia prompt (or script) call mydylib.dylib using Libdl
- and mydylib.dylib calls internally julia code as described in the documentation (example from the documentation below, in my case the body will go inside a function in a dylib instead of a main).
#include <julia.h>
JULIA_DEFINE_FAST_TLS() // only define this once, in an executable (not in a shared library) if you want fast code.
int main(int argc, char *argv[])
{
/* required: setup the Julia context */
jl_init();
/* run Julia commands */
jl_eval_string("print(sqrt(2.0))");
/* strongly recommended: notify Julia that the
program is about to terminate. this allows
Julia time to cleanup pending write requests
and run all finalizers
*/
jl_atexit_hook(0);
return 0;
}
I can ignore JULIA_DEFINE_FAST_TLS() since it’s the empty macro for MacOS (not tried on Linux yet, the comment there is a bit worrisome).
In any case it mostly works, with one exception, I need to remove jl_atexit_hook(0);
otherwise it will kill the Julia prompt, i.e. the main caller (the Julia prompt dies).
Is this expected? Is there anything else one should be worried about?
The use case is to replace a block of a C++ pipeline that lives in a dynamic library (dylib) with a prototype algorithm in Julia, and control the dylib from Julia (EDIT: or control the dylib from another language or executable).
PS
How do I control how many threads will the julia prototype alg called from inside my C++ dylib be using?