Skip to content

Threads: serialize no-GIL access to embedder allocators #54

Description

@chrisbbreuer

Parent: #1
Related: #15, #49

Problem

A preserved pre-rewrite experiment identified a valid invariant gap that remains in the current allocator architecture. Under parallel_gc, arena chunk refills are serialized by LockedArena and GC slab refills are serialized by GcCellBacking, but those are independent locks and both ultimately call the embedder-provided std.mem.Allocator. Zig allocators do not universally promise concurrent safety. Two no-GIL mutators can therefore enter a non-thread-safe embedder allocator concurrently even though each engine subsystem is internally locked.

The stale experiment itself cannot be applied: it targets the removed GC layout and points zig_gc at a deleted marker worktree. This issue tracks a clean adaptation to current main.

Acceptance criteria

  • True-parallel contexts serialize every underlying embedder allocator alloc/resize/remap/free across arena, GC backing, JIT ownership, and context side structures.
  • Single-threaded and explicit-GIL contexts add no allocator lock.
  • Heap-budget accounting and allocation-recovery lock ordering remain correct and deadlock-free.
  • Context create/error/teardown paths free the wrapper after every allocator consumer.
  • Add a concurrent probe allocator test that fails on overlapping underlying calls and passes through the wrapper.
  • Pass focused lifecycle/no-GIL semantic tests and suppression-free TSan.
  • Measure allocator contention after the fix; optimize only if Perf: remove no-GIL scaling bottlenecks in the comparison workloads #49 evidence identifies it as material.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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