(From a related issue Unsticky Tasks stick to threadpool since 1.10, causing issues since 1.12 · Issue #59936 · JuliaLang/julia · GitHub
But here I’m not referring to the functional API Task, instead, I’m talking about @spawn itself and the interactive threadpool.)
Edit: you may skip this post and see post #3 directly, which is more meaningful.
Currently there are only 2 available thread pools—:default and :interactive.
I want to run a few (e.g. one or two) computing (blocking) tasks in the non-default pool (so the only way out is to spawn them in the interactive pool.) The reason is that the default pool is reserved for other heavier tasks.
I find it not possible to achieve what I want according to the current behavior, as follows.
I launch the julia program can_it_echo.jl from the zsh in Linux.
can_it_echo.jl
println("$PROGRAM_FILE> threads_setting = $((Threads.nthreads(), Threads.nthreads(:interactive)))")
function bzwt(t) # it's merely a busy waiting function that blocks a thread for t seconds
tdue = time() + t
while true
try
@assert time() < tdue
catch e
return
end
end
end;
function main()
Threads.@spawn :interactive println("main()> begins...")
Threads.@spawn :interactive bzwt(2.5)
Threads.@spawn :interactive bzwt(2.5)
Threads.@spawn :interactive println("main()> echo")
end;
main()
Here is what I get in zsh
The results suggest that @spawn :interactive bzwt(2.5) is not flexibly scheduled so it can be run on any available idle threads within the :interactive pool—I’m having sufficiently 4 threads in this test.
(The behavior seems to be a bit random, so you are certain to reproduce the reported behavior above—the main() > echo is unseen immediately after main()> begins...—as long as you try multiple times. And this behavior is not due to insufficient threads—it occurs even if I use --threads=64,64)
The direct consequence is that: the :interactive pool is unusable other than logging messages. So given this, I’m wondering
- is there any other methods that I can create some other user pools other than the existing two? (e.g.
:default2,:default3…). So I can schedule tasks within those new pools? - What is a solution to the current situation?
