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

gh-116738: Make _abc module thread-safe#117488

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
colesbury merged 4 commits intopython:mainfromswtaarrs:cpython-_abc-module
Apr 11, 2024

Conversation

@swtaarrs
Copy link
Member

This is a collection of small changes aimed at making the_abc module safe to use in a free-threaded build:

  • Only read and write_abcmodule_state.abc_invalidation_counter and_abc_data._abc_negative_cache_version with atomic operations (except in situations when the object should only be visible to a single thread, like initialization, teardown, or GC traverse).

  • Change the two members above fromunsigned long long touint64_t. This was partially to avoid having to add more_Py_atomic_*_ullong variants, but also becauseunsigned long long is guaranteed to be at least 64 bits and I can't imagine we'd ever want more than 64. Might as well make it explicit.

  • Change_in_weak_set() and_add_to_weak_set() to both take an_abc_data * andPyObject **, to allow them to use critical sections when reading or writing the pointers to sets of weak references. None of thePyObject *s that hold a set will change once they're first initialized, so we don't need to use locking when operating on the sets, only when reading or initializing the pointers.

  • For the most part, no locks are held around multiple operations on related data structures (_abc__abc_subclasscheck_impl() being a good example). User code that does things like performing ABC subclass checks while concurrently registering subclasses will always be subject to surprising results no matter what we do internally, so the module only ensures that its data structures are kept internally consistent.

  • Two functions modify a type'stp_flags member:_abc__abc_init() (should only be called with new types not visible to other threads) and_abc__abc_register_impl() (called with existing types). I added a helper totypeobject.c to support the_abc_register case, and it was just a few more lines to also support the_abc_init case as well. This felt a bit heavy-handed so I'm open to suggestions.

  • Issue:Audit all built-in modules for thread safety #116738

Copy link
Contributor

@colesburycolesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Overall looks good. A few comments below.

@swtaarrs
Copy link
MemberAuthor

Don't merge this yet - I'm still going to make a small improvement to the refcounting offlags (hopefully after my next meeting)

colesbury reacted with thumbs up emoji

@swtaarrs
Copy link
MemberAuthor

Ok, this should be good to go once the builds finish.

@colesburycolesbury merged commitf268e32 intopython:mainApr 11, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull requestApr 17, 2024
A collection of small changes aimed at making the `_abc` module safe touse in a free-threaded build.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@colesburycolesburycolesbury approved these changes

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@swtaarrs@colesbury

[8]ページ先頭

©2009-2025 Movatter.jp