Skip to content

Track full JavaScript multithreading support #2

@chrisbbreuer

Description

@chrisbbreuer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions