Utilities for working with multithreaded "workers" in Julia services/applications
Author JuliaServices
4 Stars
Updated Last
1 Year Ago
Started In
October 2020


Utilities for working with multithreaded workers for Julia services and applications


The package is registered in the General registry and so can be installed at the REPL with ] add WorkerUtilities.



WorkerUtilities.init(nworkers=Threads.nthreads() - 1)

Initialize background workers that will execute tasks spawned via WorkerUtilities.@spawn. If nworkers == 1, a single worker will be started on thread 1 where tasks will be executed in contention with other thread 1 work. Background worker tasks can be inspected by looking at WorkerUtilities.WORKER_TASKS.


WorkerUtilities.@spawn expr
WorkerUtilities.@spawn passthroughstorage expr

Similar to Threads.@spawn, schedule and execute a task (given by expr) that will be run on a "background worker" (see WorkerUtilities.init).

In the 2-argument invocation, passthroughstorage controls whether the task-local storage of the current_task() should be "passed through" to the spawned task.


Lockable(value, lock = ReentrantLock())

Creates a Lockable object that wraps value and associates it with the provided lock.

lock(f::Function, l::Lockable)

Acquire the lock associated with l, execute f with the lock held, and release the lock when f returns. f will receive one positional argument: the value wrapped by l. If the lock is already locked by a different task/thread, wait for it to become available. When this function returns, the lock has been released, so the caller should not attempt to unlock it.

Required Packages

No packages found.

Used By Packages