We need to make the TSAN tests pass with the GIL disabled before we can disable the GIL by default in free-threaded builds.
### Tasks
- [ ] PyInterpreterState_ThreadHead
- [ ] PyThreadState_Clear
- [ ] PyThreadState_Next
- [ ] PyUnstable_InterpreterFrame_GetLine
- [ ] _PyFrame_GetCode
- [ ] _PyFrame_Initialize
- [ ] _PyObject_TryGetInstanceAttribute
- [ ] _Py_slot_tp_getattr_hook
- [x] _multiprocessing_SemLock_acquire_impl
- [x] _multiprocessing_SemLock_release_impl
- [ ] add_threadstate
- [ ] assign_version_tag
- [ ] dump_traceback
- [ ] fatal_error
- [ ] free_threadstate
- [ ] list_get_item_ref
- [x] new_reference
- [ ] pthread_create
- [ ] set_default_allocator_unlocked
- [ ] tstate_delete_common
- [ ] tstate_is_freed
- [ ] type_modified_unlocked
- [ ] write_thread_id
Feature or enhancement
We need to make the TSAN tests pass with the GIL disabled before we can disable the GIL by default in free-threaded builds.
This should proceed in two phases:
How to run the TSAN tests
env CC=clang CXX=clang++ ./configure --disable-gil --with-thread-sanitizer --with-pydebug && make -jenv TSAN_OPTIONS=suppressions=<repo_root>/Tools/tsan/suppressions_free_threading.txt ./python -m test --tsan -j4Working on a race
<repo_root>/Tools/tsan/suppressions_free_threading.txt, run the TSAN tests, and verify that the race is reported by TSAN. You may need to comment out unrelated functions (notably,_PyEval_EvalFrameDefault) in order to reproduce the race.Suppressions
Linked PRs
start_the_world()andtstate_try_attach()#117828_PySeqLock#117955tstate->state#118165_Py_IsOwnedByCurrentThread()#118258_Py_IsImmortal#118261ob_gc_bits#118292ob_gc_bits(GH-118292) #118796SemLock.__{enter,exit}__#118812SemLock.__{enter,exit}__(GH-118812) #118856interp->threads.main#118865interp->threads.main(GH-118865) #118904PyMember_GetandPyMember_Set, forPy_T_OBJECT_EXtype #119368set_discard_entry#119908set_discard_entry(GH-119908) #119914sem_clockwaitin TSAN #119915_PyEval_IsGILEnabled. #119921_PyEval_IsGILEnabled. (GH-119921) #119939sem_clockwaitin TSAN (GH-119915) #119992__slots__thread safety in free-threaded build (GH-119368) #120655PAUSE_ADAPTIVE_COUNTERin free-threaded build #122190PAUSE_ADAPTIVE_COUNTERin free-threaded build (GH-122190) #122475PyMember_GetandPyMember_Set, for C extensions #123211dict_dict_merge#129755dict_dict_merge(gh-129755) #129808compare_unicode_unicode_threadsafe#131746test_capiunder TSAN #136269