From 8f9803ddf4af7e5a8c86a347ab26637f8c9ade5b Mon Sep 17 00:00:00 2001 From: killf Date: Tue, 21 Nov 2023 07:38:25 +0800 Subject: [PATCH] asyncio: fix thread-safety issue with cached_running_holder Make `cached_running_holder` and `cached_running_holder_tsid` thread local. Co-authored-by: renpeng Co-authored-by: Sam Gross --- Modules/_asynciomodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index f30c3894abc..4ca46c47608 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -34,8 +34,8 @@ static PyObject *asyncio_CancelledError; static PyObject *context_kwname; static int module_initialized; -static PyObject *cached_running_holder; -static volatile uint64_t cached_running_holder_tsid; +static Py_DECL_THREAD PyObject *cached_running_holder; +static Py_DECL_THREAD uint64_t cached_running_holder_tsid; /* Counter for autogenerated Task names */ static uint64_t task_name_counter = 0;