René's URL Explorer Experiment


Title: Make `dict` objects thread-safe in `--disable-gil` builds · Issue #112075 · python/cpython · GitHub

Open Graph Title: Make `dict` objects thread-safe in `--disable-gil` builds · Issue #112075 · python/cpython

X Title: Make `dict` objects thread-safe in `--disable-gil` builds · Issue #112075 · python/cpython

Description: We are going to need a variety of techniques to make dictionaries thread-safe in --disable-gil builds. I expect this to be implemented across multiple PRs. For context, here is the change from the nogil-3.12 fork, but things might be don...

Open Graph Description: We are going to need a variety of techniques to make dictionaries thread-safe in --disable-gil builds. I expect this to be implemented across multiple PRs. For context, here is the change from the ...

X Description: We are going to need a variety of techniques to make dictionaries thread-safe in --disable-gil builds. I expect this to be implemented across multiple PRs. For context, here is the change from the ...

Opengraph URL: https://github.com/python/cpython/issues/112075

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make `dict` objects thread-safe in `--disable-gil` builds","articleBody":"We are going to need a variety of techniques to make dictionaries thread-safe in `--disable-gil` builds. I expect this to be implemented across multiple PRs.\r\n\r\nFor context, here is the change from the `nogil-3.12` fork, but things might be done a bit differently in CPython 3.13: https://github.com/colesbury/nogil-3.12/commit/d896dfc8db\r\n\r\n1) Most operations should acquire the dictionary object lock using the critical section API.\r\n2) Dictionary global version counter should use atomic increments \r\n3) `PyDictKeysObject` needs special handling (see below)\r\n4) `PyDictOrValues` needs special handling (see below)\r\n5) Accessing a single element should optimistically avoid locking for performance\r\n\r\nIn general, we want to avoid making changes which hurt the performance of the default build. The \"critical sections\" are no-ops in the default build, but we will need to take care with other changes. Some may be behind `#ifdef` guards.\r\n\r\n### `PyDictKeysObject`\r\n\r\nNote that `PyDictKeysObject` is *NOT* a `PyObject` subclass.\r\n\r\nWe need a mutex in `PyDictKeysObject` because multiple threads may concurrently insert keys into shared `PyDictKeysObject`. The mutex is only used for modifications to \"shared\" keys; non-shared keys rely on the locking for the dict object.\r\n\r\nIn `--disable-gil` builds, we want to avoid refcounting shared `PyDictKeysObject` for performance and thread-safety reasons. Instead shared keys objects should be freed during cyclic GC. (Non-shared keys don't need reference counting because they \"owned\" by a single dict object.) We may want to consider making this change for both the default build and `--disable-gil` builds to make maintenance easier if there is not a negative perf impact.\r\n\r\n### `PyDictOrValues`\r\n\r\n`PyDictOrValues` is the \"managed\" dict in some PyObject pre-headers. We need some locking/atomic operations to handle the transition between `PyDictValues*` and storing a `PyDictObject*`\r\n\r\n### Optimistically Avoid Locking\r\n\r\nSee https://peps.python.org/pep-0703/#optimistically-avoiding-locking.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-112247\n* gh-114256\n* gh-114508\n* gh-114512\n* gh-114543\n* gh-114568\n* gh-114629\n* gh-114741\n* gh-114742\n* gh-114768\n* gh-114778\n* gh-114931\n* gh-115108\n* gh-115109\n* gh-115786\n* gh-115855\n* gh-116087\n* gh-116336\n* gh-116344\n* gh-116620\n* gh-117528\n* gh-117529\n* gh-117824\n* gh-118499\n* gh-118676\n* gh-119288\n* gh-121545\n* gh-129336\n* gh-139737\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/colesbury","@type":"Person","name":"colesbury"},"datePublished":"2023-11-14T19:14:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/112075/cpython/issues/112075"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:774133a5-3367-080d-9c98-35f96c4cd4e0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC9AC:11169F:2A1201F:37115C3:696B2CE6
html-safe-noncebb082510e4bee99d51aac734ad74d5964c28a394dd2c6d1977dbd2988fe8e2c0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUFDOjExMTY5RjoyQTEyMDFGOjM3MTE1QzM6Njk2QjJDRTYiLCJ2aXNpdG9yX2lkIjoiODU4MzIzOTQyNjk0ODkzNDg4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace695b94c907d529b99cd420fb6c362343255e3e656b931f30069ec7c436a5d81
hovercard-subject-tagissue:1993401425
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/112075/issue_layout
twitter:imagehttps://opengraph.githubassets.com/04d44f684674effc931e688aed788cb5c73dbb60074440fda1adcab25539c232/python/cpython/issues/112075
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/04d44f684674effc931e688aed788cb5c73dbb60074440fda1adcab25539c232/python/cpython/issues/112075
og:image:altWe are going to need a variety of techniques to make dictionaries thread-safe in --disable-gil builds. I expect this to be implemented across multiple PRs. For context, here is the change from the ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecolesbury
hostnamegithub.com
expected-hostnamegithub.com
None5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release82560a55c6b2054555076f46e683151ee28a19bc
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/112075#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F112075
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F112075
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/112075
Reloadhttps://github.com/python/cpython/issues/112075
Reloadhttps://github.com/python/cpython/issues/112075
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/112075
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/112075
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/112075
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/112075
Make dict objects thread-safe in --disable-gil buildshttps://github.com/python/cpython/issues/112075#top
https://github.com/DinoV
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/colesbury
https://github.com/colesbury
colesburyhttps://github.com/colesbury
on Nov 14, 2023https://github.com/python/cpython/issues/112075#issue-1993401425
colesbury/nogil-3.12@d896dfc8dbhttps://github.com/colesbury/nogil-3.12/commit/d896dfc8db
https://peps.python.org/pep-0703/#optimistically-avoiding-lockinghttps://peps.python.org/pep-0703/#optimistically-avoiding-locking
gh-112075: Make some dict operations thread-safe without GIL #112247https://github.com/python/cpython/pull/112247
gh-112075: Adapt more dict methods to Argument Clinic #114256https://github.com/python/cpython/pull/114256
gh-112075: Add critical sections for most dict APIs #114508https://github.com/python/cpython/pull/114508
gh-112075: Add try-incref functions from nogil branch for use in dict thread safety #114512https://github.com/python/cpython/pull/114512
gh-112075: Use PyMem_* for allocating dict keys objects #114543https://github.com/python/cpython/pull/114543
gh-112075: Dictionary global version counter should use atomic increments #114568https://github.com/python/cpython/pull/114568
gh-112075: refactor dictionary lookup functions for better re-usability #114629https://github.com/python/cpython/pull/114629
gh-112075: Make PyDictKeysObject thread-safe #114741https://github.com/python/cpython/pull/114741
gh-112075: Make instance attributes stored in inline "dict" thread safe #114742https://github.com/python/cpython/pull/114742
gh-112075: Add a little specialization thread safety #114768https://github.com/python/cpython/pull/114768
gh-112075: Free-threaded dict odict basics #114778https://github.com/python/cpython/pull/114778
gh-112075: Add gc shared bits #114931https://github.com/python/cpython/pull/114931
gh-112075: Iterating a dict shouldn't require locks #115108https://github.com/python/cpython/pull/115108
gh-112075: Accessing a single element should optimistically avoid locking #115109https://github.com/python/cpython/pull/115109
gh-112075: Use relaxed stores for places where we may race with when reading lock-free #115786https://github.com/python/cpython/pull/115786
gh-112075: Remove compiler warning from apple clang #115855https://github.com/python/cpython/pull/115855
gh-112075: Avoid locking shared keys on every assignment #116087https://github.com/python/cpython/pull/116087
gh-112075: Enable freeing with qsbr and fallback to lock on key changed #116336https://github.com/python/cpython/pull/116336
gh-112075: Support freeing object memory via QSBR #116344https://github.com/python/cpython/pull/116344
gh-112075: Use atomic exchange in Py_SETREF so updating dict pointers doesn't race #116620https://github.com/python/cpython/pull/116620
gh-112075: _Py_dict_lookup needs to lock shared keys #117528https://github.com/python/cpython/pull/117528
gh-112075: Make _PyDict_LoadGlobal thread safe #117529https://github.com/python/cpython/pull/117529
gh-112075: Lock when inserting into shared keys #117824https://github.com/python/cpython/pull/117824
gh-112075: Fix race in constructing dict for instance #118499https://github.com/python/cpython/pull/118499
gh-112075: use per-thread dict version pool #118676https://github.com/python/cpython/pull/118676
gh-112075: Fix dict thread safety issues #119288https://github.com/python/cpython/pull/119288
[3.13] gh-112075: Fix dict thread safety issues (GH-119288) #121545https://github.com/python/cpython/pull/121545
gh-112075: Remove critical section in dict.get #129336https://github.com/python/cpython/pull/129336
gh-112075: Remove _PyObject_SetManagedDict() function #139737https://github.com/python/cpython/pull/139737
DinoVhttps://github.com/DinoV
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.