[ANN] DedicatedThreads.jl: thread pools created at runtime

[ANN] DedicatedThreads.jl: thread pools created at runtime

DedicatedThreads.jl lets you create thread pools from Julia code while the program runs. Julia’s :default and :interactive pools are sized at startup with -t. A pool from this package has its own OS threads, so its tasks start right away even when every :default thread is busy.

using DedicatedThreads

pool = DedicatedPool(2; name = :control)
t = spawn(() -> sum(abs2, 1:10), pool)
fetch(t)        # 385
close(pool)

:interactive also avoids a busy :default, but it is one pool, fixed at startup and shared with the REPL and anything else that uses it. With this package you can create as many pools as you need, size each one for its job, and close them when you’re done.

I wrote it for Kaimon Slate. Its notebook workers must answer status, cancel and heartbeat messages and a separate thread pool worked better than :default or :interactive for this purpose. I thought I might as well put this into a separate package in case it’s helpful for others.

Version 0.1 is in General and needs Julia 1.12 or later. The README has examples, measurements, and the limitations: GitHub - kahliburke/DedicatedThreads.jl: User-defined thread pools for Julia, created at runtime on a stock runtime · GitHub

3 Likes