René's URL Explorer Experiment


Title: Data race between `record_allocation` and `gc_get_count_impl` · Issue #150411 · python/cpython · GitHub

Open Graph Title: Data race between `record_allocation` and `gc_get_count_impl` · Issue #150411 · python/cpython

X Title: Data race between `record_allocation` and `gc_get_count_impl` · Issue #150411 · python/cpython

Description: Bug report Bug description: I found this during solve #148613. The gc_generation.count has one read not protected by atomic operation. import gc from threading import Barrier, Thread class CyclicReference: def __init__(self): self.ref = ...

Open Graph Description: Bug report Bug description: I found this during solve #148613. The gc_generation.count has one read not protected by atomic operation. import gc from threading import Barrier, Thread class CyclicRe...

X Description: Bug report Bug description: I found this during solve #148613. The gc_generation.count has one read not protected by atomic operation. import gc from threading import Barrier, Thread class CyclicRe...

Opengraph URL: https://github.com/python/cpython/issues/150411

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Data race between `record_allocation` and `gc_get_count_impl`","articleBody":"# Bug report\n\n### Bug description:\n\nI found this during solve #148613.\n\nThe `gc_generation.count` has one read not protected by atomic operation.\n\n```python\nimport gc\nfrom threading import Barrier, Thread\n\nclass CyclicReference:\n    def __init__(self):\n        self.ref = self\n\nN_ALLOCATORS = 7\nN_READERS = 1\nN_THREADS = N_ALLOCATORS + N_READERS\nN_ITERS = 200_000\n\nbarrier = Barrier(N_THREADS)\n\ndef allocator():\n    barrier.wait()\n    for _ in range(N_ITERS):\n        CyclicReference()\n\n\ndef reader():\n    barrier.wait()\n    for _ in range(N_ITERS):\n        gc.get_count()\n\nthreads = [Thread(target=allocator) for _ in range(N_ALLOCATORS)]\nthreads.extend(Thread(target=reader) for _ in range(N_READERS))\n\nfor thread in threads:\n    thread.start()\nfor thread in threads:\n    thread.join()\n```\n\nHere is tsan report.\n\n```\n==================\nWARNING: ThreadSanitizer: data race (pid=2274087)\n  Atomic write of size 4 at 0x55a842f6ab04 by thread T2:\n    #0 _Py_atomic_add_int Include/cpython/pyatomic_gcc.h:15 (python3.16+0x45a310)\n    #1 record_allocation Python/gc_free_threading.c:2028 (python3.16+0x45a310)\n    #2 _PyObject_GC_Link Python/gc_free_threading.c:2707 (python3.16+0x45a310)\n    #3 _PyType_AllocNoTrack Objects/typeobject.c:2533 (python3.16+0x299867)\n    #4 PyType_GenericAlloc Objects/typeobject.c:2554 (python3.16+0x2998d4)\n    #5 _PyEval_EvalFrameDefault Python/generated_cases.c.h:1955 (python3.16+0x3e0047)\n    #6 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee7b7)\n    #7 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee7b7)\n    #8 _PyFunction_Vectorcall Objects/call.c:413 (python3.16+0x152190)\n    #9 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x15379f)\n    #10 _PyObject_VectorcallPrepend Objects/call.c:855 (python3.16+0x15379f)\n    #11 method_vectorcall Objects/classobject.c:55 (python3.16+0x158676)\n    #12 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x42927b)\n    #13 context_run Python/context.c:728 (python3.16+0x42927b)\n    #14 method_vectorcall_FASTCALL_KEYWORDS Objects/descrobject.c:421 (python3.16+0x174575)\n    #15 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x151d7c)\n    #16 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151d7c)\n    #17 _Py_VectorCallInstrumentation_StackRefSteal Python/ceval.c:775 (python3.16+0x3c13f5)\n    #18 _PyEval_EvalFrameDefault Python/generated_cases.c.h:1846 (python3.16+0x3cee3f)\n    #19 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee7b7)\n    #20 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee7b7)\n    #21 _PyFunction_Vectorcall Objects/call.c:413 (python3.16+0x152190)\n    #22 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x15379f)\n    #23 _PyObject_VectorcallPrepend Objects/call.c:855 (python3.16+0x15379f)\n    #24 method_vectorcall Objects/classobject.c:55 (python3.16+0x158676)\n    #25 _PyVectorcall_Call Objects/call.c:273 (python3.16+0x154c78)\n    #26 _PyObject_Call Objects/call.c:348 (python3.16+0x1550b1)\n    #27 PyObject_Call Objects/call.c:373 (python3.16+0x1550b1)\n    #28 thread_run Modules/_threadmodule.c:388 (python3.16+0x609d30)\n    #29 pythread_wrapper Python/thread_pthread.h:234 (python3.16+0x508c52)\n    #30 \u003cnull\u003e \u003cnull\u003e (libtsan.so.2+0x4cf1a)\n\n  Previous read of size 4 at 0x55a842f6ab04 by thread T8:\n    #0 gc_get_count_impl Modules/gcmodule.c:232 (python3.16+0x52aef1)\n    #1 gc_get_count Modules/clinic/gcmodule.c.h:305 (python3.16+0x52aef1)\n    #2 cfunction_vectorcall_NOARGS Objects/methodobject.c:508 (python3.16+0x21a586)\n    #3 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x151d7c)\n    #4 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151d7c)\n    #5 _Py_VectorCall_StackRefSteal Python/ceval.c:733 (python3.16+0x3c0fc5)\n    #6 _PyEval_EvalFrameDefault Python/generated_cases.c.h:4362 (python3.16+0x3cf022)\n    #7 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee7b7)\n    #8 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee7b7)\n    #9 _PyFunction_Vectorcall Objects/call.c:413 (python3.16+0x152190)\n    #10 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x15379f)\n    #11 _PyObject_VectorcallPrepend Objects/call.c:855 (python3.16+0x15379f)\n    #12 method_vectorcall Objects/classobject.c:55 (python3.16+0x158676)\n    #13 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x42927b)\n    #14 context_run Python/context.c:728 (python3.16+0x42927b)\n    #15 method_vectorcall_FASTCALL_KEYWORDS Objects/descrobject.c:421 (python3.16+0x174575)\n    #16 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x151d7c)\n    #17 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151d7c)\n    #18 _Py_VectorCallInstrumentation_StackRefSteal Python/ceval.c:775 (python3.16+0x3c13f5)\n    #19 _PyEval_EvalFrameDefault Python/generated_cases.c.h:1846 (python3.16+0x3cee3f)\n    #20 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee7b7)\n    #21 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee7b7)\n    #22 _PyFunction_Vectorcall Objects/call.c:413 (python3.16+0x152190)\n    #23 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x15379f)\n    #24 _PyObject_VectorcallPrepend Objects/call.c:855 (python3.16+0x15379f)\n    #25 method_vectorcall Objects/classobject.c:55 (python3.16+0x158676)\n    #26 _PyVectorcall_Call Objects/call.c:273 (python3.16+0x154c78)\n    #27 _PyObject_Call Objects/call.c:348 (python3.16+0x1550b1)\n    #28 PyObject_Call Objects/call.c:373 (python3.16+0x1550b1)\n    #29 thread_run Modules/_threadmodule.c:388 (python3.16+0x609d30)\n    #30 pythread_wrapper Python/thread_pthread.h:234 (python3.16+0x508c52)\n    #31 \u003cnull\u003e \u003cnull\u003e (libtsan.so.2+0x4cf1a)\n\n  Location is global '_PyRuntime' of size 405696 at 0x55a842f42240 (python3.16+0x89fb04)\n\n  Thread T2 'Thread-2 (alloc' (tid=2274090, running) created by main thread at:\n    #0 pthread_create \u003cnull\u003e (libtsan.so.2+0x58491)\n    #1 do_start_joinable_thread Python/thread_pthread.h:281 (python3.16+0x508d67)\n    #2 PyThread_start_joinable_thread Python/thread_pthread.h:323 (python3.16+0x5090ab)\n    #3 ThreadHandle_start Modules/_threadmodule.c:475 (python3.16+0x60aca9)\n    #4 do_start_new_thread Modules/_threadmodule.c:1919 (python3.16+0x60aca9)\n    #5 thread_PyThread_start_joinable_thread Modules/_threadmodule.c:2042 (python3.16+0x60b5b9)\n    #6 cfunction_call Objects/methodobject.c:564 (python3.16+0x2192fd)\n    #7 _PyObject_MakeTpCall Objects/call.c:242 (python3.16+0x150e5b)\n    #8 _PyObject_VectorcallTstate Include/internal/pycore_call.h:142 (python3.16+0x151de1)\n    #9 _PyObject_VectorcallTstate Include/internal/pycore_call.h:129 (python3.16+0x151de1)\n    #10 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151de1)\n    #11 _Py_VectorCall_StackRefSteal Python/ceval.c:733 (python3.16+0x3c0fc5)\n    #12 _PyEval_EvalFrameDefault Python/generated_cases.c.h:3528 (python3.16+0x3d8f55)\n    #13 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee06c)\n    #14 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee06c)\n    #15 PyEval_EvalCode Python/ceval.c:686 (python3.16+0x3ee06c)\n    #16 run_eval_code_obj Python/pythonrun.c:1369 (python3.16+0x4d55c2)\n    #17 run_mod Python/pythonrun.c:1472 (python3.16+0x4d5b88)\n    #18 pyrun_file Python/pythonrun.c:1296 (python3.16+0x4d9913)\n    #19 _PyRun_SimpleFileObject Python/pythonrun.c:518 (python3.16+0x4d9913)\n    #20 _PyRun_AnyFileObject Python/pythonrun.c:81 (python3.16+0x4da3c5)\n    #21 pymain_run_file_obj Modules/main.c:411 (python3.16+0x52940d)\n    #22 pymain_run_file Modules/main.c:430 (python3.16+0x52940d)\n    #23 pymain_run_python Modules/main.c:715 (python3.16+0x52940d)\n    #24 Py_RunMain Modules/main.c:796 (python3.16+0x52a2fd)\n    #25 pymain_main Modules/main.c:826 (python3.16+0x52a2fd)\n    #26 Py_BytesMain Modules/main.c:850 (python3.16+0x52a2fd)\n    #27 main Programs/python.c:15 (python3.16+0xa0786)\n\n  Thread T8 'Thread-8 (reade' (tid=2274096, running) created by main thread at:\n    #0 pthread_create \u003cnull\u003e (libtsan.so.2+0x58491)\n    #1 do_start_joinable_thread Python/thread_pthread.h:281 (python3.16+0x508d67)\n    #2 PyThread_start_joinable_thread Python/thread_pthread.h:323 (python3.16+0x5090ab)\n    #3 ThreadHandle_start Modules/_threadmodule.c:475 (python3.16+0x60aca9)\n    #4 do_start_new_thread Modules/_threadmodule.c:1919 (python3.16+0x60aca9)\n    #5 thread_PyThread_start_joinable_thread Modules/_threadmodule.c:2042 (python3.16+0x60b5b9)\n    #6 cfunction_call Objects/methodobject.c:564 (python3.16+0x2192fd)\n    #7 _PyObject_MakeTpCall Objects/call.c:242 (python3.16+0x150e5b)\n    #8 _PyObject_VectorcallTstate Include/internal/pycore_call.h:142 (python3.16+0x151de1)\n    #9 _PyObject_VectorcallTstate Include/internal/pycore_call.h:129 (python3.16+0x151de1)\n    #10 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151de1)\n    #11 _Py_VectorCall_StackRefSteal Python/ceval.c:733 (python3.16+0x3c0fc5)\n    #12 _PyEval_EvalFrameDefault Python/generated_cases.c.h:3528 (python3.16+0x3d8f55)\n    #13 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee06c)\n    #14 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee06c)\n    #15 PyEval_EvalCode Python/ceval.c:686 (python3.16+0x3ee06c)\n    #16 run_eval_code_obj Python/pythonrun.c:1369 (python3.16+0x4d55c2)\n    #17 run_mod Python/pythonrun.c:1472 (python3.16+0x4d5b88)\n    #18 pyrun_file Python/pythonrun.c:1296 (python3.16+0x4d9913)\n    #19 _PyRun_SimpleFileObject Python/pythonrun.c:518 (python3.16+0x4d9913)\n    #20 _PyRun_AnyFileObject Python/pythonrun.c:81 (python3.16+0x4da3c5)\n    #21 pymain_run_file_obj Modules/main.c:411 (python3.16+0x52940d)\n    #22 pymain_run_file Modules/main.c:430 (python3.16+0x52940d)\n    #23 pymain_run_python Modules/main.c:715 (python3.16+0x52940d)\n    #24 Py_RunMain Modules/main.c:796 (python3.16+0x52a2fd)\n    #25 pymain_main Modules/main.c:826 (python3.16+0x52a2fd)\n    #26 Py_BytesMain Modules/main.c:850 (python3.16+0x52a2fd)\n    #27 main Programs/python.c:15 (python3.16+0xa0786)\n\nSUMMARY: ThreadSanitizer: data race Include/cpython/pyatomic_gcc.h:15 in _Py_atomic_add_int\n==================\n==================\nWARNING: ThreadSanitizer: data race (pid=2274087)\n  Atomic write of size 4 at 0x55a842f6ab04 by thread T3:\n    #0 _Py_atomic_compare_exchange_int Include/cpython/pyatomic_gcc.h:70 (python3.16+0x45b47f)\n    #1 record_deallocation Python/gc_free_threading.c:2057 (python3.16+0x45b47f)\n    #2 PyObject_GC_Del Python/gc_free_threading.c:2831 (python3.16+0x45b47f)\n    #3 object_dealloc Objects/typeobject.c:7463 (python3.16+0x286bab)\n    #4 subtype_dealloc Objects/typeobject.c:2871 (python3.16+0x28e8b7)\n    #5 _Py_Dealloc Objects/object.c:3312 (python3.16+0x22599b)\n    #6 _Py_DecRefSharedDebug Objects/object.c:426 (python3.16+0x225d5d)\n    #7 _Py_DecRefShared Objects/object.c:433 (python3.16+0x225d5d)\n    #8 Py_DECREF Include/refcount.h:385 (python3.16+0x45ca4c)\n    #9 delete_garbage Python/gc_free_threading.c:1769 (python3.16+0x45ca4c)\n    #10 gc_collect_internal Python/gc_free_threading.c:2176 (python3.16+0x45ca4c)\n    #11 gc_collect_main Python/gc_free_threading.c:2257 (python3.16+0x45d5d6)\n    #12 _Py_RunGC Python/gc_free_threading.c:2716 (python3.16+0x45dbb6)\n    #13 _Py_HandlePending Python/ceval_gil.c:1399 (python3.16+0x46d393)\n    #14 check_periodics Python/ceval_macros.h:524 (python3.16+0x3e9e88)\n    #15 _PyEval_EvalFrameDefault Python/generated_cases.c.h:10876 (python3.16+0x3e9e88)\n    #16 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee7b7)\n    #17 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee7b7)\n    #18 _PyFunction_Vectorcall Objects/call.c:413 (python3.16+0x152190)\n    #19 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x15379f)\n    #20 _PyObject_VectorcallPrepend Objects/call.c:855 (python3.16+0x15379f)\n    #21 method_vectorcall Objects/classobject.c:55 (python3.16+0x158676)\n    #22 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x42927b)\n    #23 context_run Python/context.c:728 (python3.16+0x42927b)\n    #24 method_vectorcall_FASTCALL_KEYWORDS Objects/descrobject.c:421 (python3.16+0x174575)\n    #25 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x151d7c)\n    #26 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151d7c)\n    #27 _Py_VectorCallInstrumentation_StackRefSteal Python/ceval.c:775 (python3.16+0x3c13f5)\n    #28 _PyEval_EvalFrameDefault Python/generated_cases.c.h:1846 (python3.16+0x3cee3f)\n    #29 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee7b7)\n    #30 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee7b7)\n    #31 _PyFunction_Vectorcall Objects/call.c:413 (python3.16+0x152190)\n    #32 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x15379f)\n    #33 _PyObject_VectorcallPrepend Objects/call.c:855 (python3.16+0x15379f)\n    #34 method_vectorcall Objects/classobject.c:55 (python3.16+0x158676)\n    #35 _PyVectorcall_Call Objects/call.c:273 (python3.16+0x154c78)\n    #36 _PyObject_Call Objects/call.c:348 (python3.16+0x1550b1)\n    #37 PyObject_Call Objects/call.c:373 (python3.16+0x1550b1)\n    #38 thread_run Modules/_threadmodule.c:388 (python3.16+0x609d30)\n    #39 pythread_wrapper Python/thread_pthread.h:234 (python3.16+0x508c52)\n    #40 \u003cnull\u003e \u003cnull\u003e (libtsan.so.2+0x4cf1a)\n\n  Previous read of size 4 at 0x55a842f6ab04 by thread T8:\n    #0 gc_get_count_impl Modules/gcmodule.c:232 (python3.16+0x52aef1)\n    #1 gc_get_count Modules/clinic/gcmodule.c.h:305 (python3.16+0x52aef1)\n    #2 cfunction_vectorcall_NOARGS Objects/methodobject.c:508 (python3.16+0x21a586)\n    #3 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x151d7c)\n    #4 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151d7c)\n    #5 _Py_VectorCall_StackRefSteal Python/ceval.c:733 (python3.16+0x3c0fc5)\n    #6 _PyEval_EvalFrameDefault Python/generated_cases.c.h:4362 (python3.16+0x3cf022)\n    #7 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee7b7)\n    #8 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee7b7)\n    #9 _PyFunction_Vectorcall Objects/call.c:413 (python3.16+0x152190)\n    #10 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x15379f)\n    #11 _PyObject_VectorcallPrepend Objects/call.c:855 (python3.16+0x15379f)\n    #12 method_vectorcall Objects/classobject.c:55 (python3.16+0x158676)\n    #13 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x42927b)\n    #14 context_run Python/context.c:728 (python3.16+0x42927b)\n    #15 method_vectorcall_FASTCALL_KEYWORDS Objects/descrobject.c:421 (python3.16+0x174575)\n    #16 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x151d7c)\n    #17 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151d7c)\n    #18 _Py_VectorCallInstrumentation_StackRefSteal Python/ceval.c:775 (python3.16+0x3c13f5)\n    #19 _PyEval_EvalFrameDefault Python/generated_cases.c.h:1846 (python3.16+0x3cee3f)\n    #20 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee7b7)\n    #21 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee7b7)\n    #22 _PyFunction_Vectorcall Objects/call.c:413 (python3.16+0x152190)\n    #23 _PyObject_VectorcallTstate Include/internal/pycore_call.h:144 (python3.16+0x15379f)\n    #24 _PyObject_VectorcallPrepend Objects/call.c:855 (python3.16+0x15379f)\n    #25 method_vectorcall Objects/classobject.c:55 (python3.16+0x158676)\n    #26 _PyVectorcall_Call Objects/call.c:273 (python3.16+0x154c78)\n    #27 _PyObject_Call Objects/call.c:348 (python3.16+0x1550b1)\n    #28 PyObject_Call Objects/call.c:373 (python3.16+0x1550b1)\n    #29 thread_run Modules/_threadmodule.c:388 (python3.16+0x609d30)\n    #30 pythread_wrapper Python/thread_pthread.h:234 (python3.16+0x508c52)\n    #31 \u003cnull\u003e \u003cnull\u003e (libtsan.so.2+0x4cf1a)\n\n  Location is global '_PyRuntime' of size 405696 at 0x55a842f42240 (python3.16+0x89fb04)\n\n  Thread T3 'Thread-3 (alloc' (tid=2274091, running) created by main thread at:\n    #0 pthread_create \u003cnull\u003e (libtsan.so.2+0x58491)\n    #1 do_start_joinable_thread Python/thread_pthread.h:281 (python3.16+0x508d67)\n    #2 PyThread_start_joinable_thread Python/thread_pthread.h:323 (python3.16+0x5090ab)\n    #3 ThreadHandle_start Modules/_threadmodule.c:475 (python3.16+0x60aca9)\n    #4 do_start_new_thread Modules/_threadmodule.c:1919 (python3.16+0x60aca9)\n    #5 thread_PyThread_start_joinable_thread Modules/_threadmodule.c:2042 (python3.16+0x60b5b9)\n    #6 cfunction_call Objects/methodobject.c:564 (python3.16+0x2192fd)\n    #7 _PyObject_MakeTpCall Objects/call.c:242 (python3.16+0x150e5b)\n    #8 _PyObject_VectorcallTstate Include/internal/pycore_call.h:142 (python3.16+0x151de1)\n    #9 _PyObject_VectorcallTstate Include/internal/pycore_call.h:129 (python3.16+0x151de1)\n    #10 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151de1)\n    #11 _Py_VectorCall_StackRefSteal Python/ceval.c:733 (python3.16+0x3c0fc5)\n    #12 _PyEval_EvalFrameDefault Python/generated_cases.c.h:3528 (python3.16+0x3d8f55)\n    #13 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee06c)\n    #14 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee06c)\n    #15 PyEval_EvalCode Python/ceval.c:686 (python3.16+0x3ee06c)\n    #16 run_eval_code_obj Python/pythonrun.c:1369 (python3.16+0x4d55c2)\n    #17 run_mod Python/pythonrun.c:1472 (python3.16+0x4d5b88)\n    #18 pyrun_file Python/pythonrun.c:1296 (python3.16+0x4d9913)\n    #19 _PyRun_SimpleFileObject Python/pythonrun.c:518 (python3.16+0x4d9913)\n    #20 _PyRun_AnyFileObject Python/pythonrun.c:81 (python3.16+0x4da3c5)\n    #21 pymain_run_file_obj Modules/main.c:411 (python3.16+0x52940d)\n    #22 pymain_run_file Modules/main.c:430 (python3.16+0x52940d)\n    #23 pymain_run_python Modules/main.c:715 (python3.16+0x52940d)\n    #24 Py_RunMain Modules/main.c:796 (python3.16+0x52a2fd)\n    #25 pymain_main Modules/main.c:826 (python3.16+0x52a2fd)\n    #26 Py_BytesMain Modules/main.c:850 (python3.16+0x52a2fd)\n    #27 main Programs/python.c:15 (python3.16+0xa0786)\n\n  Thread T8 'Thread-8 (reade' (tid=2274096, running) created by main thread at:\n    #0 pthread_create \u003cnull\u003e (libtsan.so.2+0x58491)\n    #1 do_start_joinable_thread Python/thread_pthread.h:281 (python3.16+0x508d67)\n    #2 PyThread_start_joinable_thread Python/thread_pthread.h:323 (python3.16+0x5090ab)\n    #3 ThreadHandle_start Modules/_threadmodule.c:475 (python3.16+0x60aca9)\n    #4 do_start_new_thread Modules/_threadmodule.c:1919 (python3.16+0x60aca9)\n    #5 thread_PyThread_start_joinable_thread Modules/_threadmodule.c:2042 (python3.16+0x60b5b9)\n    #6 cfunction_call Objects/methodobject.c:564 (python3.16+0x2192fd)\n    #7 _PyObject_MakeTpCall Objects/call.c:242 (python3.16+0x150e5b)\n    #8 _PyObject_VectorcallTstate Include/internal/pycore_call.h:142 (python3.16+0x151de1)\n    #9 _PyObject_VectorcallTstate Include/internal/pycore_call.h:129 (python3.16+0x151de1)\n    #10 PyObject_Vectorcall Objects/call.c:327 (python3.16+0x151de1)\n    #11 _Py_VectorCall_StackRefSteal Python/ceval.c:733 (python3.16+0x3c0fc5)\n    #12 _PyEval_EvalFrameDefault Python/generated_cases.c.h:3528 (python3.16+0x3d8f55)\n    #13 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122 (python3.16+0x3ee06c)\n    #14 _PyEval_Vector Python/ceval.c:2156 (python3.16+0x3ee06c)\n    #15 PyEval_EvalCode Python/ceval.c:686 (python3.16+0x3ee06c)\n    #16 run_eval_code_obj Python/pythonrun.c:1369 (python3.16+0x4d55c2)\n    #17 run_mod Python/pythonrun.c:1472 (python3.16+0x4d5b88)\n    #18 pyrun_file Python/pythonrun.c:1296 (python3.16+0x4d9913)\n    #19 _PyRun_SimpleFileObject Python/pythonrun.c:518 (python3.16+0x4d9913)\n    #20 _PyRun_AnyFileObject Python/pythonrun.c:81 (python3.16+0x4da3c5)\n    #21 pymain_run_file_obj Modules/main.c:411 (python3.16+0x52940d)\n    #22 pymain_run_file Modules/main.c:430 (python3.16+0x52940d)\n    #23 pymain_run_python Modules/main.c:715 (python3.16+0x52940d)\n    #24 Py_RunMain Modules/main.c:796 (python3.16+0x52a2fd)\n    #25 pymain_main Modules/main.c:826 (python3.16+0x52a2fd)\n    #26 Py_BytesMain Modules/main.c:850 (python3.16+0x52a2fd)\n    #27 main Programs/python.c:15 (python3.16+0xa0786)\n\nSUMMARY: ThreadSanitizer: data race Include/cpython/pyatomic_gcc.h:70 in _Py_atomic_compare_exchange_int\n==================\nThreadSanitizer: reported 2 warnings\n```\n\n## Root Cause\n\nThis problem would happen when cyclic references allocation frequently in free threading build.\n\nThe `alloc_count` would be reset when `gc-\u003ealloc_count \u003e= LOCAL_ALLOC_COUNT_THRESHOLD` and the `gcstate-\u003eyoung.count` would increase.\nhttps://github.com/python/cpython/blob/c714b5679817099ac574890392f408129e6c67cb/Python/gc_free_threading.c#L2025-L2029\n\nAnd we read the count in `gc_get_count_impl`, it was partially protected by atomic.\nhttps://github.com/python/cpython/blob/c714b5679817099ac574890392f408129e6c67cb/Modules/gcmodule.c#L211-L237\n\n## Solution\n\nSo we should add atomic load for the read action.\n\nFor `count` in `gc_collect_internal`, they are guarded by STW so I think they should be safe.\nhttps://github.com/python/cpython/blob/c714b5679817099ac574890392f408129e6c67cb/Python/gc_free_threading.c#L2065-L2077\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-150413\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/LindaSummer","@type":"Person","name":"LindaSummer"},"datePublished":"2026-05-25T16:03:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/150411/cpython/issues/150411"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d27e194c-1682-9e6b-fafb-04ad26129177
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE9D0:386175:23FE:2D4F:6A577461
html-safe-nonceeff61ee7d954d093946f82de7f96846203ddf1ab0c7abb57560bf5dcd5e97fb6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUQwOjM4NjE3NToyM0ZFOjJENEY6NkE1Nzc0NjEiLCJ2aXNpdG9yX2lkIjoiMzkyODMwNzAyNjM1MTMyMjIwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacad2620968deb6610e3810b160fa289ec8d0b59a89b8918f64c7002ae3392e60b
hovercard-subject-tagissue:4518155395
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/150411/issue_layout
twitter:imagehttps://opengraph.githubassets.com/84e536c4745bd5a7799bdd61ecc1a2c6378a2505857a37feb803ea0e1c734faa/python/cpython/issues/150411
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/84e536c4745bd5a7799bdd61ecc1a2c6378a2505857a37feb803ea0e1c734faa/python/cpython/issues/150411
og:image:altBug report Bug description: I found this during solve #148613. The gc_generation.count has one read not protected by atomic operation. import gc from threading import Barrier, Thread class CyclicRe...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameLindaSummer
hostnamegithub.com
expected-hostnamegithub.com
None4e7a7296a3830877cf21a6ad2a972c9e618a48915e03966cf0c53eb08e5aad98
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasec0ca805e53f128ba1f966be1d3ccd81d0d1959c7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/150411#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F150411
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F150411
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/150411
Reloadhttps://github.com/python/cpython/issues/150411
Reloadhttps://github.com/python/cpython/issues/150411
Please reload this pagehttps://github.com/python/cpython/issues/150411
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/150411
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Data race between record_allocation and gc_get_count_implhttps://github.com/python/cpython/issues/150411#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/LindaSummer
LindaSummerhttps://github.com/LindaSummer
on May 25, 2026https://github.com/python/cpython/issues/150411#issue-4518155395
#148613https://github.com/python/cpython/issues/148613
cpython/Python/gc_free_threading.chttps://github.com/python/cpython/blob/c714b5679817099ac574890392f408129e6c67cb/Python/gc_free_threading.c#L2025-L2029
c714b56https://github.com/python/cpython/commit/c714b5679817099ac574890392f408129e6c67cb
cpython/Modules/gcmodule.chttps://github.com/python/cpython/blob/c714b5679817099ac574890392f408129e6c67cb/Modules/gcmodule.c#L211-L237
c714b56https://github.com/python/cpython/commit/c714b5679817099ac574890392f408129e6c67cb
cpython/Python/gc_free_threading.chttps://github.com/python/cpython/blob/c714b5679817099ac574890392f408129e6c67cb/Python/gc_free_threading.c#L2065-L2077
c714b56https://github.com/python/cpython/commit/c714b5679817099ac574890392f408129e6c67cb
gh-150411: fix gc_generation.count race #150413https://github.com/python/cpython/pull/150413
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.