Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kumaraditya303 opened this issue Feb 18, 2025 · 1 comment
Closed

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

kumaraditya303 opened this issue Feb 18, 2025 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading

Comments

@kumaraditya303
Copy link
Contributor

kumaraditya303 commented Feb 18, 2025

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

@kumaraditya303
Copy link
Contributor Author

Fixed by 388e1ca

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading
Projects
None yet
Development

No branches or pull requests

1 participant