Skip to content

list iterator and list reverse iterator are not thread safe #130263

Closed
@kumaraditya303

Description

@kumaraditya303

While reviewing #130096, I checked the thread safety of list object and there at some places we are missing atomic stores of index.

Specifically the following:

  • cpython/Objects/listobject.c

    Lines 3994 to 3997 in 97d0011

    else if (index > PyList_GET_SIZE(it->it_seq))
    index = PyList_GET_SIZE(it->it_seq); /* iterator exhausted */
    it->it_index = index;
    }
  • cpython/Objects/listobject.c

    Lines 4146 to 4149 in 97d0011

    else if (index > PyList_GET_SIZE(it->it_seq) - 1)
    index = PyList_GET_SIZE(it->it_seq) - 1;
    it->it_index = index;
    }

They should use atomic relaxed stores.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions