TSAN complains on free-threaded list operations #130920
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
Discovered a case where TSAN complains about list operations in free-threaded build and posting it here on the suggestion of @colesbury.
Reproducer:
Error (also happens in the other direction, write after read):
Relevant locations in files:
Write:
cpython/Python/generated_cases.c.h
Line 11262 in 052cb71
Read:
cpython/Python/generated_cases.c.h
Line 686 in 052cb71
What is happening probably is that the read is a lock-free read which occurs in the other thread between the
PyList_SET_ITEM()
and theUNLOCK_OBJECT()
. In order to avoid TSAN complaining here either thePyList_SET_ITEM()
and the read would have to be atomic, or the read would have to be locked with a mutex (negating the point of lock-free).The thing is as far as I see the worst thing that will happen on the read side is it will get a stale value from the list. Which since there is not a defined order between the threads is harmless since the read can easily have happened before the modification or after regardless. So is this an issue and should the write (and read) be made atomic during lock-free operation (or some other correction applied)?
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: