# Embedding Julia into multithreading apps

**URL:** <https://discourse.julialang.org/t/embedding-julia-into-multithreading-apps/20122>\
**Category:** Internals & Design\
**Created:** [January 26, 2019, 9:17am UTC](https://discourse.julialang.org/t/embedding-julia-into-multithreading-apps/20122 "2019-01-26T09:17:39Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [January 27, 2019, 12:53pm UTC](https://discourse.julialang.org/t/embedding-julia-into-multithreading-apps/20122/10 "2019-01-27T12:53:36Z")

</div>

> [@tobias.knopp](#):
>
> So can I quote you with this statement:  
> “The julia embedding C API is thread safe”

Yes.

> [@tobias.knopp](#):
>
> Because this is what the OP asked about. It was not asked if Julia internally is thread safe, it was asked about embedding of Julia.

No. he is from the start just not even asking about only the thread safety at all. He is asking about the thread related limitation on the API. There are much more (thread related) properties on the API then what you can cover with just “threadsafety”.

> [@tobias.knopp](#):
>
> “The public Julia embedding API is not fully thread safe. There might be functions that are thread safe but those are not documented and marked as such. Therefore it is recommend as a user of the API to prevent concurrent accesses to Julia API functions.”

Still wrong.

Pretty much the only function that is not meant to be threadsafe is the init functions, which cannot be called from multiple thread for reasons completely unrelated to threading as explained above. The **only** limitations are,

1. It’s pretty much still experimental since we know there’s bug but almost all functions are meant to be threadsafe, if only for the reason that pretty much all of those functions are called by julia itself from multiple threads. This is why it may not be fully documented/marked.

2. Extenal thread is not supported, which is a limitation that’s fairly orthogonal to the general meaning of “threadsafe”.

Again, there are multiple tiers of thread safety. Calling it “not thread safe” means it doesn’t even have a basic level of thread support and julia’s embedding API is well passed that. I take this meaning from your word since you are using it to imply that “Therefore it is recommend as a user of the API to prevent concurrent accesses to Julia API functions”, which is just wrong. Concurrent access of julia API function is no less supported or recommended than using multiple threads in julia itself.

> [@tobias.knopp](#):
>
> My statement “Julia is not thread safe” might have been to generic

And yes, it’s way too generic. That’s exactly what I’m complaining about because it’s misleading and have led you to the wrong conclusion. You can say `jl_init` is not thread safe, which at least isn’t wrong even though the reason is largely irrelevant to thread… Or better you should say it doesn’t support external thread, which is the **actual** limitation.

---

_[View the full topic](https://discourse.julialang.org/t/embedding-julia-into-multithreading-apps/20122)._
