Skip to content

Add fiber pools besides the default carrier pool - #1307

Merged
yogthos merged 2 commits into
mainfrom
feat/fiber-pools
Oct 11, 2026
Merged

yogthos merged 2 commits into
mainfrom
feat/fiber-pools

Conversation

@yogthos

@yogthos yogthos commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Fibers are pinned to their carrier for life, so a fiber in a blocking foreign call strands every fiber queued behind it, and the default pool is the only place to put anything. This adds named pools with their own carriers:

(def io (fib/pool {:name :io :size 8}))
(fib/spawn f {:pool io})
(fib/pool-of fib)   ; => io, nil for the default pool
(fib/shutdown! io)

Parks, resumes, interrupt! and kill! already go through the fiber's own carrier record, so they work across pools without changes. The default pool's code paths are unchanged apart from spawn being split into pick + spawn-on.

shutdown! refuses new spawns, and each carrier exits only once the fibers placed on it have finished, parked ones included. The live count sits on the carrier under its mu, raised at spawn and lowered by a fiber monitor, so default fibers don't pay for it.

This is for ensemble's Akka-style dispatchers (jlt-commons/ensemble#12).

Tested with the new test/chez/jolt-fiber-pools-test.clj (wired into smoke.sh), which includes a usleep FFI call pinning one pool's carrier while another pool keeps running, plus make fibers, manifestcheck, lockcheck and parkcheck.

A fiber is pinned to its carrier for life, so a fiber stuck in a blocking
foreign call strands everything queued on its carrier, and there was only
the one pool to put it in. jolt.fibers/pool starts a separate set of
carriers, and (spawn f {:pool p}) places a fiber on one of them. Parks,
resumes, interrupts and kills already go through the fiber's own carrier,
so they work across pools unchanged; the default pool's paths are not
touched.

shutdown! refuses new spawns but each carrier keeps running until the
fibers placed on it have finished, parked ones included. That count lives
on the carrier and is lowered by a monitor on each pool fiber.

The record is jolt-pool rather than jolt-fiber-pool because the latter's
mu accessor would shadow the existing jolt-fiber-pool-mu.
A pool made before the first default spawn ran on the default quantum
regardless of *fiber-preempt-ticks*.
@yogthos
yogthos merged commit 00c97ec into main Oct 11, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant