Title: gh-116738: Make _abc module thread-safe by swtaarrs · Pull Request #117488 · python/cpython · GitHub
Open Graph Title: gh-116738: Make _abc module thread-safe by swtaarrs · Pull Request #117488 · python/cpython
X Title: gh-116738: Make _abc module thread-safe by swtaarrs · Pull Request #117488 · python/cpython
Description: 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 from unsigned long long to uint64_t. This was partially to avoid having to add more _Py_atomic_*_ullong variants, but also because unsigned 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 * and PyObject **, to allow them to use critical sections when reading or writing the pointers to sets of weak references. None of the PyObject *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's tp_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 to typeobject.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: gh-116738
Open Graph Description: 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_negati...
X Description: 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_negati...
Opengraph URL: https://github.com/python/cpython/pull/117488
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:501bc6db-1c8c-0c31-af7f-79621574b4c6 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | 8BA0:29957D:1D3455D:2822A0B:696ABDA1 |
| html-safe-nonce | 38c4c6d85ce585dd1198f497fc0822ab398fd95292009eaf26230c299df96ef7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QkEwOjI5OTU3RDoxRDM0NTVEOjI4MjJBMEI6Njk2QUJEQTEiLCJ2aXNpdG9yX2lkIjoiNDMxNDczOTU2NjI2Mjc5NTY4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bc1ad1d897fadb0e36b71bd61946e7ec861d49ccb21a17365330eaf9aeb06fa5 |
| hovercard-subject-tag | pull_request:1803487529 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/117488/checks |
| twitter:image | https://avatars.githubusercontent.com/u/118219?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/118219?s=400&v=4 |
| og:image:alt | 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_negati... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 46ce962e0e18113ea447391b6ace8b02d4d2861e57b4fbab3658698f73d8855b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 30300f30bb3949de255e84a146706a3bdb5c19c9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width