You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It has been oft-requested that we have a dedicated IO thread. That
actually turns out to already be the case of something that exists,
except that we hard-code the identity of that thread as being thread 0.
This PR replaces all of the places where we hard code that assumption
with a variable so that they are more easily searched for in the code.
It also adds an internal function (`jl_set_io_loop_tid`) that can be
used to transfer ownership of the loop to any (valid) tid. In
conjunction with the prior foreign-threads work and foreign-thread pool,
this lets us spawn a dedicate IO-management thread with this bit of
code:
```julia
function make_io_thread()
tid = UInt[0]
threadwork = @cfunction function(arg::Ptr{Cvoid})
Base.errormonitor(current_task()) # this may not go particularly well if the IO loop is dead, but try anyways
@CCall jl_set_io_loop_tid((Threads.threadid() - 1)::Int16)::Cvoid
wait() # spin uv_run as long as needed
nothing
end Cvoid (Ptr{Cvoid},)
err = @CCall uv_thread_create(tid::Ptr{UInt}, threadwork::Ptr{Cvoid}, C_NULL::Ptr{Cvoid})::Cint
err == 0 || Base.uv_error("uv_thread_create", err)
@CCall uv_thread_detach(tid::Ptr{UInt})::Cint
err == 0 || Base.uv_error("uv_thread_detach", err)
# n.b. this does not wait for the thread to start or to take ownership of the event loop
nothing
end
```
0 commit comments