Skip to content

feat: add create Options, per-fiber data, and reset for pooling - #4

Merged
itsakeyfut merged 4 commits into
mainfrom
feat/create-options-data-reset
Jul 22, 2026
Merged

feat: add create Options, per-fiber data, and reset for pooling#4
itsakeyfut merged 4 commits into
mainfrom
feat/create-options-data-reset

Conversation

@itsakeyfut

@itsakeyfut itsakeyfut commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Make Fiber usable as the building block for a pooling scheduler: attach a per-fiber payload, choose the stack size, and recycle finished fibers without reallocating.

Changes

  • data payload — a public data: ?*anyopaque = null field on Fiber, so a scheduler can associate a fiber with a runtime-created task instead of generating a function per task at comptime. Read it in the entry via fiber.data.
  • create options (breaking)create(allocator, entry, options: Options) where Options = struct { stack_size: usize = 64*1024, data: ?*anyopaque = null }. Pass .{} for the previous defaults. Every in-repo call site (examples + tests) is updated.
  • reset for reusereset(entry, data) re-arms a finished (or never-started) fiber with a new entry and data, reusing the same stack allocation (the pooling primitive). It reinitializes the stack via setupStack and must not be called on a running or suspended fiber.
  • README + CHANGELOG (Added + Changed) updated.

Pure Zig — no inline assembly changed.

Related Issues

Test Plan

  • zig build compiles cleanly
  • zig build test passes (14 tests, Windows) — including data-payload, custom-stack-size, and reset-reuse-with-suspend/resume tests
  • zig build examples runs both examples
  • zig fmt --check . passes
  • CI green on ubuntu-latest and windows-latest

Give Fiber a public data: ?*anyopaque payload and move create to an Options
struct (stack_size, data), so a scheduler can attach runtime task state to a
fiber without generating a function per task at comptime. Breaking: create now
takes an options argument; pass .{} for the previous defaults. Every in-repo
call site (examples and tests) is updated.
Re-arm a finished or never-started fiber with a new entry and data, reusing the
same stack allocation, so a scheduler can maintain a fiber pool and recycle
fibers between jobs instead of paying a stack allocation per job.
@itsakeyfut itsakeyfut self-assigned this Jul 22, 2026
@itsakeyfut
itsakeyfut merged commit d103ed1 into main Jul 22, 2026
2 checks passed
@itsakeyfut
itsakeyfut deleted the feat/create-options-data-reset branch July 22, 2026 14:37
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