Skip to content

Commit 4ca1e31

Browse files
committed
Stop-the-world requests should block new threads.
Starting in the "suspended" state blocks any _PyThreadState_Attach() call until the stop-the-world event completes.
1 parent 71ffa1d commit 4ca1e31

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Python/pystate.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,11 @@ init_threadstate(_PyThreadStateImpl *_tstate,
13311331
tstate->datastack_limit = NULL;
13321332
tstate->what_event = -1;
13331333

1334+
if (interp->stoptheworld.requested || _PyRuntime.stoptheworld.requested) {
1335+
// Start in the suspended state if there is an ongoing stop-the-world.
1336+
tstate->state = _Py_THREAD_SUSPENDED;
1337+
}
1338+
13341339
tstate->_status.initialized = 1;
13351340
}
13361341

0 commit comments

Comments
 (0)