Skip to content

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Feb 13, 2025

This moves tstate_activate() down to avoid a data race in the free threading build on the _PyRuntime's thread-local autoTSSkey. This key is deleted during runtime finalization, which may happen concurrently with a call to _PyThreadState_Attach.

The earlier tstate_try/wait_attach ensures that the thread is blocked before it attempts to access the deleted autoTSSkey.

This fixes a TSAN reported data race in
test_threading.test_import_from_another_thread.

This moves `tstate_activate()` down to avoid a data race in the free
threading build on the `_PyRuntime`'s thread-local `autoTSSkey`. This
key is deleted during runtime finalization, which may happen
concurrently with a call to `_PyThreadState_Attach`.

The earlier `tstate_try/wait_attach` ensures that the thread is blocked
before it attempts to access the deleted `autoTSSkey`.

This fixes a TSAN reported data race in
`test_threading.test_import_from_another_thread`.
@colesbury colesbury merged commit 7aeaa5a into python:main Feb 27, 2025
51 checks passed
@colesbury colesbury deleted the gh-130091-tstate-attach branch February 27, 2025 18:57
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…ythongh-130092)

This moves `tstate_activate()` down to avoid a data race in the free
threading build on the `_PyRuntime`'s thread-local `autoTSSkey`. This
key is deleted during runtime finalization, which may happen
concurrently with a call to `_PyThreadState_Attach`.

The earlier `tstate_try/wait_attach` ensures that the thread is blocked
before it attempts to access the deleted `autoTSSkey`.

This fixes a TSAN reported data race in
`test_threading.test_import_from_another_thread`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants