10000 gh-117300: Use stop the world to make `sys._current_frames` and · colesbury/cpython@214c3a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 214c3a1

Browse files
committed
pythongh-117300: Use stop the world to make sys._current_frames and
`sys._current_exceptions` thread-safe. This adds a stop the world pause to make the two functions thread-safe when the GIL is disabled in the free-threaded build.
1 parent 262fb91 commit 214c3a1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Python/pystate.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,7 @@ _PyThread_CurrentFrames(void)
24062406
* Because these lists can mutate even when the GIL is held, we
24072407
* need to grab head_mutex for the duration.
24082408
*/
2409+
_PyEval_StopTheWorldAll(runtime);
24092410
HEAD_LOCK(runtime);
24102411
PyInterpreterState *i;
24112412
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
@@ -2439,6 +2440,7 @@ _PyThread_CurrentFrames(void)
24392440

24402441
done:
24412442
HEAD_UNLOCK(runtime);
2443+
_PyEval_StartTheWorldAll(runtime);
24422444
return result;
24432445
}
24442446

@@ -2470,6 +2472,7 @@ _PyThread_CurrentExceptions(void)
24702472
* Because these lists can mutate even when the GIL is held, we
24712473
* need to grab head_mutex for the duration.
24722474
*/
2475+
_PyEval_StopTheWorldAll(runtime);
24732476
HEAD_LOCK(runtime);
24742477
PyInterpreterState *i;
24752478
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
@@ -2502,6 +2505,7 @@ _PyThread_CurrentExceptions(void)
25022505

25032506
done:
25042507
HEAD_UNLOCK(runtime);
2508+
_PyEval_StartTheWorldAll(runtime);
25052509
return result;
25062510
}
25072511

0 commit comments

Comments
 (0)
0