Skip to content

TSan warning on lock unparking #149045

@dpdani

Description

@dpdani

Bug report

Bug description:

I've hit this TSan warning a few times while working on something else:

WARNING: ThreadSanitizer: data race (pid=99297)
  Write of size 4 at 0x00016d2d24f0 by thread T71:
    #0 mutex_unpark lock.c:187 (python.exe:arm64+0x100190868)
    #1 _PyParkingLot_Unpark parking_lot.c:377 (python.exe:arm64+0x10019793c)
    #2 PyMember_SetOne structmember.c:327 (python.exe:arm64+0x1001a6224)
    #3 PyObject_GenericSetAttr object.c:2120 (python.exe:arm64+0x1000a3940)
    #4 pythread_wrapper thread_pthread.h:234 (python.exe:arm64+0x1001b785c)

  Previous write of size 8 at 0x00016d2d24f0 by thread T72:
    #0 _PyMutex_LockTimed lock.c:78 (python.exe:arm64+0x1001905b4)
    #1 PyMutex_Lock lock.c:647 (python.exe:arm64+0x100191644)
    #2 _PyCriticalSection_BeginSlow critical_section.c:59 (python.exe:arm64+0x10016a508)
    #3 PyObject_GenericGetAttr object.c:2012 (python.exe:arm64+0x1000a28fc)
    #4 pythread_wrapper thread_pthread.h:234 (python.exe:arm64+0x1001b785c)

  Location is stack of thread T72.

  Thread T71 (tid=1323228, running) created by main thread at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x335b8)
    #1 do_start_joinable_thread thread_pthread.h:281 (python.exe:arm64+0x1001b7504)
    #2 do_start_new_thread _threadmodule.c:1919 (python.exe:arm64+0x1002674bc)
    #3 thread_PyThread_start_joinable_thread _threadmodule.c:2042 (python.exe:arm64+0x100266564)
    #4 cfunction_call methodobject.c:564 (python.exe:arm64+0x10009b4cc)

  Thread T72 (tid=1323229, running) created by main thread at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x335b8)
    #1 do_start_joinable_thread thread_pthread.h:281 (python.exe:arm64+0x1001b7504)
    #2 do_start_new_thread _threadmodule.c:1919 (python.exe:arm64+0x1002674bc)
    #3 thread_PyThread_start_joinable_thread _threadmodule.c:2042 (python.exe:arm64+0x100266564)
    #4 cfunction_call methodobject.c:564 (python.exe:arm64+0x10009b4cc)

SUMMARY: ThreadSanitizer: data race lock.c:187 in mutex_unpark

The conflict is between the initialization write and the later write by the unlocking thread.

I think this is not an actual issue in practice, and the second write could be marked as ignored.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions