Skip to content

Data race in dk_nentries #153881

Description

@brijkapadia

Bug report

Bug description:

This is a sub-issue of #153852 with the gist here.


This reproducer crashes in free-threaded build with TSan:

import threading

ROUNDS = 10000

box = [None]
enter = threading.Barrier(2)
leave = threading.Barrier(2)

def reader():
    for _ in range(ROUNDS):
        enter.wait()
        obj = box[0]
        obj.__getstate__()
        leave.wait()

def writer():
    for i in range(ROUNDS):
        box[0] = type(f"C{i}", (), {})()
        enter.wait()
        obj = box[0]
        setattr(obj, f"{i}", 1)
        leave.wait()

threads = [threading.Thread(target=reader), threading.Thread(target=writer)]

for thread in threads:
    thread.start()

for thread in threads:
    thread.join()

See the gist for more information.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions