jobs

Garnet threading primitives - the shared job pool, frame pipelines, command queues and owner-thread release queues

garnet-jobs

Garnet's threading and garbage-collection runtime primitives. It depends on nothing else in Garnet, so lower-level shards (content, physics, audio) can use it without the ECS. require "garnet-ecs" also loads it.

  • Garnet::Jobs: the shared, bounded worker pool (parallel_for, dispatch/Batch, submit/Future, try_submit (never runs inline; returns nil when there are no workers or the queue is full), Future#join (waits without running the job here), worker_index, idle?). Jobs::Task plus dispatch(task, count, chunk_size:) is the reusable, allocation-free form of dispatch for hot native task systems (Box2D).
  • Garnet::Pipeline(T): hands one value per frame to a consumer on its own owner thread, with back-pressure.
  • Garnet::CommandQueue(T): a bounded, lock-free, allocation-free single-producer single-consumer ring.
  • Garnet::ReleaseQueue: native releases deferred from GC finalizers to the resource's owner thread.
  • Garnet::GCRuntime: bdwgc scheduling switches (automatic collection on and off, explicit and unmapping collections, parallel marker start-up, GC_do_blocking), native-memory pressure accounting and a non-allocating pause probe.

See docs/threading.md and docs/gc.md for the design and measurements.

Parallelism needs -Dpreview_mt -Dexecution_context; without those flags every job runs inline on the caller with the same results.

require "garnet-jobs"

jobs = Garnet::Jobs.shared
jobs.parallel_for(items.size, chunk_size: 256) do |range, _chunk|
  range.each { |index| results[index] = decode(items[index]) }
end
Repository

jobs

Owner
Statistic
  • 0
  • 0
  • 0
  • 7
  • 0
  • 1 day ago
  • November 30, 2026
License

MIT License

Links
Synced at

Wed, 02 Dec 2026 02:08:50 GMT

Languages