Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Lib/test/test_free_threading/test_threading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest
from test.support import threading_helper

threading_helper.requires_working_threading(module=True)


class TestRlock(unittest.TestCase):
def test_repr_race(self):
# gh-153292
import _thread
r = _thread.RLock()

def repr_thread():
for _ in range(2000):
repr(r)

def mutate_thread():
for _ in range(2000):
r.acquire()
r.release()

threading_helper.run_concurrently([repr_thread, mutate_thread])


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix data race in repr of :class:`threading.RLock` in free-threading build.
2 changes: 1 addition & 1 deletion Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ static PyObject *
rlock_repr(PyObject *op)
{
rlockobject *self = rlockobject_CAST(op);
PyThread_ident_t owner = self->lock.thread;
PyThread_ident_t owner = FT_ATOMIC_LOAD_ULLONG_RELAXED(self->lock.thread);
int locked = rlock_locked_impl(self);
size_t count;
if (locked) {
Expand Down
Loading