ReviewOS

zig-utils/zig-js

Track full JavaScript multithreading support

#2
Closed chris opened this 9 days ago ·
9 days ago

Goal

Track the work needed to move zig-js from the current experimental shared-realm Thread API to full JavaScript multithreading with worker-style agents, shared memory, and eventually shared structured data.

Current state

  • Context.createWith(.{ .enable_threads = true }) exposes experimental Thread, Lock, Condition, ThreadLocal, and property Atomics.wait support.
  • The vendored WebKit PR-249 threads allowlist is green at 27/27.
  • The implementation is still serialized by a VM lock and does not yet provide full worker agents or test262 $262.agent coverage.

Work to build

  • Define agent boundaries: Context ownership, agent-local C-API handles, and allowed cross-thread values.
  • Add worker agents: one Context per OS thread with its own global object, realms, job queues, allocator state, module hooks, cancellation, and teardown.
  • Implement structured clone and transfer: structuredClone, message passing, ArrayBuffer transfer/detach, and worker lifecycle host hooks.
  • Finish the shared-memory baseline: SharedArrayBuffer storage, typed-array views over shared storage, Atomics, Atomics.wait/notify, and the real test262 $262.agent harness.
  • Specify scheduling: separate per-agent microtask queues from host task queues, define blocking behavior, and keep promise ordering deterministic.
  • Replace or contain arena lifetimes before shared objects can escape between agents; future GC work needs roots, write barriers, and cross-agent ownership rules.
  • Grow concurrency coverage: PR-249 corpus, transfer/detach races, shared typed-array atomics, worker teardown, and host callback reentrancy.

TC39 structs

Track https://github.com/tc39/proposal-structs as a likely future layer. Shared structs, fixed layouts, Atomics.Mutex, and Atomics.Condition could provide a good data model for parallel JS once worker agents, structured clone, SharedArrayBuffer, and Atomics are correct.

Milestone signal

A useful first milestone is: worker agents + structured clone + SharedArrayBuffer/Atomics + $262.agent harness green enough to score the relevant test262 concurrency tests without host failures.

9 days ago

Closing as a duplicate of #1. Threading work should be tracked in the canonical issue only so docs, implementation status, PR-249 allowlist counts, GC/zig-gc work, and TC39 structs tracking do not drift across multiple similar roadmap issues.

Sign in to comment on this issue.