[3.14] gh-137400: Fix thread-safety issues when profiling all threads (gh-137518) (gh-137730)

There were a few thread-safety issues when profiling or tracing all
threads via PyEval_SetProfileAllThreads or PyEval_SetTraceAllThreads:

* The loop over thread states could crash if a thread exits concurrently
  (in both the free threading and default build)
* The modification of `c_profilefunc` and `c_tracefunc` wasn't
  thread-safe on the free threading build.
(cherry picked from commit a10152f8fd)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Sam Gross 2025-10-07 13:45:23 -04:00 committed by GitHub
parent c1cb785ebd
commit fb699effbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 432 additions and 245 deletions

View file

@ -0,0 +1,5 @@
Fix a crash in the :term:`free threading` build when disabling profiling or
tracing across all threads with :c:func:`PyEval_SetProfileAllThreads` or
:c:func:`PyEval_SetTraceAllThreads` or their Python equivalents
:func:`threading.settrace_all_threads` and
:func:`threading.setprofile_all_threads`.