Skip to content

gh-153928: make Unicode iterators thread-safe - #155873

Open
BHUVANSH855 wants to merge 3 commits into
python:mainfrom
BHUVANSH855:fix-153928-unicode-iterator-thread-safety
Open

gh-153928: make Unicode iterators thread-safe#155873
BHUVANSH855 wants to merge 3 commits into
python:mainfrom
BHUVANSH855:fix-153928-unicode-iterator-thread-safety

Conversation

@BHUVANSH855

@BHUVANSH855 BHUVANSH855 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix data races in Unicode iterators in free-threaded builds.

This makes it_index accesses atomic in both Unicode iterator implementations and atomically exchanges it_seq when the iterator is exhausted so that only one thread releases the iterator-owned reference.

__length_hint__ and __reduce__ also take a strong reference to the underlying string under a critical section before accessing it.

Adds free-threading regression tests covering shared string iteration and concurrent iterator exhaustion.

Fixes issue gh-153928.

Comment thread Objects/unicodeobject.c Outdated
@BHUVANSH855
BHUVANSH855 requested a review from picnixz August 15, 2026 21:46
@BHUVANSH855
BHUVANSH855 marked this pull request as ready for review August 15, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants