Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Makelist objects thread-safe in--disable-gil builds #112087

Closed
Assignees
corona10
Labels
@colesbury

Description

@colesbury

Feature or enhancement

I expect this to be implemented across multiple PRs.

For context, here is the change from thenogil-3.12 fork, but things might be done a bit differently in CPython 3.13:colesbury/nogil-3.12@df4c51f82b.

  • Most operations should acquire the list object lock using the critical section API.
  • Accessing a single element should optimistically avoid locking for performance
  • Iterators need some special handling
  • list.sort

Iterators

For performance reasons, we don't want to acquire locks while iterating over lists. This means that list iterators have a lesser notion of thread-safety: multiple threads concurrently using the sameiterator should not crash but may revisit elements. We should make clear in the documentation that iterators are not generally thread-safe. From an implementation point of view, we should use relaxed atomics to update theit_index variable.

Additionally, we don't want to clear theit_seq reference to the list when the iterator is exhausted in--disable-gil builds. Doing so would pose thread-safety issues (in the "may segfault sense").

I don't expect this to pose any issues for real code. While it's fairly common to share lists between threads, it's rare to share the same iterator object between threads.

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp