summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2024-11-19 19:59:19 (GMT)
committerGitHub <noreply@github.com>2024-11-19 19:59:19 (GMT)
commit1c0a104eca189a932e0b44ca9bef46cce3d0b801 (patch)
tree3b619bb0e18539e8e7e55f31739cb8779d7ba19a /Include
parent824afbf548e7128ca57c6faf45cfd6b066a6ee45 (diff)
downloadcpython-1c0a104eca189a932e0b44ca9bef46cce3d0b801.zip
cpython-1c0a104eca189a932e0b44ca9bef46cce3d0b801.tar.gz
cpython-1c0a104eca189a932e0b44ca9bef46cce3d0b801.tar.bz2
gh-126914: Store the Preallocated Thread State's Pointer in a PyInterpreterState Field (gh-126989)
This approach eliminates the originally reported race. It also gets rid of the deadlock reported in gh-96071, so we can remove the workaround added then.
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_interp.h4
-rw-r--r--Include/internal/pycore_runtime_init.h3
2 files changed, 6 insertions, 1 deletions
diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h
index 824b865..5e4bcbf 100644
--- a/Include/internal/pycore_interp.h
+++ b/Include/internal/pycore_interp.h
@@ -130,6 +130,7 @@ struct _is {
uint64_t next_unique_id;
/* The linked list of threads, newest first. */
PyThreadState *head;
+ _PyThreadStateImpl *preallocated;
/* The thread currently executing in the __main__ module, if any. */
PyThreadState *main;
/* Used in Modules/_threadmodule.c. */
@@ -278,9 +279,10 @@ struct _is {
struct _Py_interp_cached_objects cached_objects;
struct _Py_interp_static_objects static_objects;
+ Py_ssize_t _interactive_src_count;
+
/* the initial PyInterpreterState.threads.head */
_PyThreadStateImpl _initial_thread;
- Py_ssize_t _interactive_src_count;
};
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index 8a8f476..9f67489 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -118,6 +118,9 @@ extern PyTypeObject _PyExc_MemoryError;
{ \
.id_refcount = -1, \
._whence = _PyInterpreterState_WHENCE_NOTSET, \
+ .threads = { \
+ .preallocated = &(INTERP)._initial_thread, \
+ }, \
.imports = IMPORTS_INIT, \
.ceval = { \
.recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \