Skip to content

Race in concurrent iteration over range iterators #129068

Description

@Yhg1s

Bug report

Bug description:

Concurrent iteration over range iterators (not range objects themselves) is not thread-safe, because range iterators are currently implemented as two pieces of state (the next value and the number of values left) that aren't updated atomically. ThreadSanitizer correctly identifies these races as well. See tests in PR #128637, and an early attempt at fixing the issues in 1533d1d.

This also affects bytecode specialisation (FOR_ITER_RANGE), although in PR #128798 we're only specialising if the iterator is uniquely referenced (and so we don't care about other threads).

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions