You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix --native subinterpreter merge for shared TIDs using shim stack anchors
When multiple subinterpreters execute on the same OS thread, each
PyThread previously received the full native stack for that TID. That
made native/Python merging fail because every thread in the group saw
the same set of eval frames, so n_eval did not match each thread's
entry-frame count.
This change makes native merging deterministic for same-TID
subinterpreter groups.
The game is played like this:
- Capture a per-thread stack anchor in the native layer:
- add Thread::StackAnchor() and d_stack_anchor.
- compute the anchor from the Python frame chain by walking backwards
to the nearest stack/shim-owned frame (FRAME_OWNED_BY_INTERPRETER /
FRAME_OWNED_BY_CSTACK on 3.14+, FRAME_OWNED_BY_CSTACK on 3.12/3.13).
- Thread construction now forwards this anchor into PyThread as stack_anchor.
- Switch process/core thread assembly from immediate yielding to collect-then-normalize.
- Group Python threads by tid when native mode is enabled.
- For groups with more than one thread:
- pick a canonical native stack,
- sort group members by stack_anchor (stable tie-breaker),
- partition eval-frame ownership according to each thread's Python entry-frame count,
- slice native frames accordingly per thread.
- If counts are inconsistent, keep existing behavior for that group and skip slicing.
0 commit comments