I’ve been trying to get a simple multi-threaded example to crash on my end here, but no luck so far. For example:
// gcc -pthread -o t_threading `julia /usr/share/julia/julia-config.jl --cflags --ldflags --ldlibs` t_threading.c
#include <julia/julia.h>
JULIA_DEFINE_FAST_TLS
void *func(void*)
{
jl_init();
jl_eval_string("println(Threads.nthreads())");
jl_eval_string("x=[1]; @time Threads.@threads for i in 1:100 global x=hcat(x,size(rand(10000,1000))); end");
jl_atexit_hook(0);
return NULL;
}
int main()
{
pthread_t t;
pthread_create(&t, NULL, func, NULL);
pthread_join(t, NULL);
}
Note that there are some implied restrictions when embedding in a multi-threaded environment. The docs don’t mentioned these, but threads like this one suggest that calling Julia API functions from a thread that was not started by Julia is unsupported, and doing so could lead to all kinds of nasty behaviour. So to put simply, you should only call jl_...
functions from either the thread in which jl_init()
was called, or from a thread that was started by Julia (and not from some other thread you started). Can you show some of your code to see what it does?
And does this segfault occur already the first time you run your plugin? Or does it take multiple runs?