Calling Julia Callback from a Different Thread

127 views
Skip to first unread message

VHaravy

unread,
May 21, 2013, 6:22:28 AM5/21/13
to juli...@googlegroups.com
Is it safe to call Julia callback obtained via cfunction from a different thread? For example, I obtain a pointer to a Julia function via cfunction, then pass this pointer to some C functions (via ccall). This C function is then creates a thread from and calls Julia callback by pointer from this thread. There is no race here, all calls are made from exactly one thread that happens to be different from Julia's main thread. I keep getting some random crashes in similar scenario and wondering whether it is safe at all (MATLAB, for example, does not this).

Steven G. Johnson

unread,
May 21, 2013, 10:21:03 AM5/21/13
to juli...@googlegroups.com
On Tuesday, May 21, 2013 6:22:28 AM UTC-4, VHaravy wrote:
Is it safe to call Julia callback obtained via cfunction from a different thread?
 
No.  The Julia library, and especially the memory allocation and garbage collection, is not currently thread-safe (see https://github.com/JuliaLang/julia/issues/1790 and https://github.com/JuliaLang/julia/pull/1002).   That means it is not in general possible to call back to the Julia runtime from a different thread.

(It might conceivably work for very special callback functions that do no memory allocation or JIT compilation, but it hard to make any guarantees.)
Reply all
Reply to author
Forward
0 new messages