I have an external library which requires thread local resources to function. For every thread Julia creates, it must notify this library via an initialize_thread_local() function. Is there a way to run this code for each OS thread that Julia spawns? @everywhere only runs on each process and not thread. Is the best option Threads.@threads :static?
The best option is probably a TaskLocalValue (OncePerTask on Julia 1.12+) from TaskLocalValues.jl. (That assumes this is a C-style “threading context”
that you pass into the ccalls you’re making).
Julia tasks can migrate threads, so it’s not safe to simply assume that a task will remain on the thread it started on.
In this case I do not need to track any thread local context. The external library sets up thread local contextes when I call initialize_thread_local()