Hello,
Calling compiled Julia 0.5 code from C++ (MSVS15) from multiple threads a
code that follows fails.
Consider following example under WIN using Julia 0.5:
#include <thread>
#include <iostream>
#include "julia.h"
//@Base.ccallable Int64 jl_foo(x::Int64) = (x + 1)
void TestJl()
{
jl_options.compile_enabled = JL_OPTIONS_COMPILE_OFF;
jl_options.startupfile = JL_OPTIONS_STARTUPFILE_OFF;
jl_options.use_precompiled = JL_OPTIONS_USE_PRECOMPILED_YES;
jl_init_with_image(NULL, "myJulia.dll");
jl_function_t *func1 = jl_get_function(jl_main_module, "jl_foo");
jl_value_t* in = jl_box_int64(1);
jl_value_t* ret = NULL;
JL_GC_PUSH2(&in, &ret);
// use computation in Julia here ...
ret = jl_call1(func1, in);
std::cout << "returned: " << jl_unbox_int64(ret) << "\n";
JL_GC_POP();
jl_atexit_hook(0);
}
int main()
{
std::vector<std::thread> threads;
for (size_t i = 0; i < 5; ++i)
{
threads.emplace_back(std::thread{ TestJl });
}
for (size_t i = 0; i < threads.size(); ++i)
{
threads[i].join();
}
return 0;
}
Error message: ": for the -enable-tail-merge option: may only occur zero or
one times!"
Single threaded version (just call TestJL()) as well 1thread-version (1
thread in the for loop) works fine.
Please, can anyone give some hints/explanation, if calling code from
compiled Julia is possible from multiple threads?