René's URL Explorer Experiment


Title: Data race between `gc_should_collect` and `gc_set_threshold_impl` · Issue #148613 · python/cpython · GitHub

Open Graph Title: Data race between `gc_should_collect` and `gc_set_threshold_impl` · Issue #148613 · python/cpython

X Title: Data race between `gc_should_collect` and `gc_set_threshold_impl` · Issue #148613 · python/cpython

Description: Bug report Bug description: gc_set_threshold_impl writes gcstate->young.threshold cpython/Modules/gcmodule.c Lines 154 to 161 in 69e0a78 static PyObject * gc_set_threshold_impl(PyObject *module, int threshold0, int group_right_1, int thr...

Open Graph Description: Bug report Bug description: gc_set_threshold_impl writes gcstate->young.threshold cpython/Modules/gcmodule.c Lines 154 to 161 in 69e0a78 static PyObject * gc_set_threshold_impl(PyObject *module, in...

X Description: Bug report Bug description: gc_set_threshold_impl writes gcstate->young.threshold cpython/Modules/gcmodule.c Lines 154 to 161 in 69e0a78 static PyObject * gc_set_threshold_impl(PyObject *module,...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Data race between `gc_should_collect` and `gc_set_threshold_impl`","articleBody":"# Bug report\n\n### Bug description:\n\n`gc_set_threshold_impl` writes `gcstate-\u003eyoung.threshold`\nhttps://github.com/python/cpython/blob/69e0a78e6edc3166c7a5b166955c0cefd1bacd5d/Modules/gcmodule.c#L154-L161\n\nwhile `gc_should_collect()` reads `gcstate-\u003eyoung.threshold` non atomically\nhttps://github.com/python/cpython/blob/69e0a78e6edc3166c7a5b166955c0cefd1bacd5d/Python/gc_free_threading.c#L2198-L2203\n\nReproducer:\n\n```python\nimport sys\nimport gc\nfrom threading import Thread, Barrier\n\nclass C:\n    pass\n\nN_THREADS = 8\nN_ITERS = 100_000\nbarrier = Barrier(N_THREADS)\n\ndef allocator():\n    barrier.wait()\n    keep = []\n    for i in range(N_ITERS):\n        a = C(); b = C()\n        a.r = b; b.r = a\n        if i % 100 == 0:\n            keep.append(a)\n            if len(keep) \u003e 1000:\n                keep.clear()\n\ndef setter():\n    barrier.wait()\n    for i in range(N_ITERS):\n        gc.set_threshold(100 + (i \u0026 0x3F), 10, 10)\n\nthreads = [Thread(target=allocator) for _ in range(N_THREADS - 1)]\nthreads.append(Thread(target=setter))\nfor t in threads: t.start()\nfor t in threads: t.join()\n```\n\nTSAN Report:\n```\nWARNING: ThreadSanitizer: data race (pid=482463)\n  Read of size 4 at 0x555555e38f80 by thread T5:\n    #0 gc_should_collect_mem_usage /cpython/Python/gc_free_threading.c:2168:36 (python3.15t+0x4a90c3) \n    #1 gc_should_collect /cpython/Python/gc_free_threading.c:2217:12 (python3.15t+0x4a90c3)\n    #2 record_allocation /cpython/Python/gc_free_threading.c:2234:13 (python3.15t+0x4a8324) \n    #3 _PyObject_GC_Link /cpython/Python/gc_free_threading.c:2914:5 (python3.15t+0x4a8324)\n    #4 _PyType_AllocNoTrack /cpython/Objects/typeobject.c:2537:9 (python3.15t+0x322b3d) \n    #5 PyType_GenericAlloc /cpython/Objects/typeobject.c:2558:21 (python3.15t+0x32291e) \n    #6 object_new /cpython/Objects/typeobject.c:7340:21 (python3.15t+0x32ed3b) \n    #7 type_call /cpython/Objects/typeobject.c:2471:11 (python3.15t+0x32a7e2) \n    #8 _PyObject_MakeTpCall /cpython/Objects/call.c:242:18 (python3.15t+0x20ef0f) \n    #9 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:142:16 (python3.15t+0x20fcf7) \n    #10 PyObject_Vectorcall /cpython/Objects/call.c:327:12 (python3.15t+0x20fcf7)\n    #11 _Py_VectorCall_StackRefSteal /cpython/Python/ceval.c:733:11 (python3.15t+0x428ab9) \n    #12 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:4344:35 (python3.15t+0x435c37) \n    #13 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x428660) \n    #14 _PyEval_Vector /cpython/Python/ceval.c:2124:12 (python3.15t+0x428660)\n    #15 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x2102af) \n    #16 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x211de9) \n    #17 _PyObject_VectorcallPrepend /cpython/Objects/call.c:855:20 (python3.15t+0x211de9)\n    #18 method_vectorcall /cpython/Objects/classobject.c:55:12 (python3.15t+0x21531f) \n    #19 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x480a91) \n    #20 context_run /cpython/Python/context.c:727:29 (python3.15t+0x480a91)\n    #21 method_vectorcall_FASTCALL_KEYWORDS /cpython/Objects/descrobject.c:421:24 (python3.15t+0x229fe7) \n    #22 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x20fc33) \n    #23 PyObject_Vectorcall /cpython/Objects/call.c:327:12 (python3.15t+0x20fc33)\n    #24 _Py_VectorCallInstrumentation_StackRefSteal /cpython/Python/ceval.c:775:11 (python3.15t+0x42928c) \n    #25 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:1841:35 (python3.15t+0x42f07c) \n    #26 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x428660) \n    #27 _PyEval_Vector /cpython/Python/ceval.c:2124:12 (python3.15t+0x428660)\n    #28 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x2102af) \n    #29 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x211de9) \n    #30 _PyObject_VectorcallPrepend /cpython/Objects/call.c:855:20 (python3.15t+0x211de9)\n    #31 method_vectorcall /cpython/Objects/classobject.c:55:12 (python3.15t+0x21531f) \n    #32 _PyVectorcall_Call /cpython/Objects/call.c:273:16 (python3.15t+0x20ff3b) \n    #33 _PyObject_Call /cpython/Objects/call.c:348:16 (python3.15t+0x20ff3b)\n    #34 PyObject_Call /cpython/Objects/call.c:373:12 (python3.15t+0x20ffa5) \n    #35 thread_run /cpython/./Modules/_threadmodule.c:388:21 (python3.15t+0x605bc2) \n    #36 pythread_wrapper /cpython/Python/thread_pthread.h:234:5 (python3.15t+0x535427) \n  Previous write of size 4 at 0x555555e38f80 by thread T8:\n    #0 gc_set_threshold_impl /cpython/Modules/gcmodule.c:161:30 (python3.15t+0x5510f6) \n    #1 gc_set_threshold /cpython/Modules/clinic/gcmodule.c.h:266:20 (python3.15t+0x5510f6)\n    #2 cfunction_call /cpython/Objects/methodobject.c:575:18 (python3.15t+0x2c10d1) \n    #3 _PyObject_MakeTpCall /cpython/Objects/call.c:242:18 (python3.15t+0x20ef0f) \n    #4 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:142:16 (python3.15t+0x20fcf7) \n    #5 PyObject_Vectorcall /cpython/Objects/call.c:327:12 (python3.15t+0x20fcf7)\n    #6 _Py_VectorCall_StackRefSteal /cpython/Python/ceval.c:733:11 (python3.15t+0x428ab9) \n    #7 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:4344:35 (python3.15t+0x435c37) \n    #8 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x428660) \n    #9 _PyEval_Vector /cpython/Python/ceval.c:2124:12 (python3.15t+0x428660)\n    #10 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x2102af) \n    #11 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x211de9) \n    #12 _PyObject_VectorcallPrepend /cpython/Objects/call.c:855:20 (python3.15t+0x211de9)\n    #13 method_vectorcall /cpython/Objects/classobject.c:55:12 (python3.15t+0x21531f) \n    #14 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x480a91) \n    #15 context_run /cpython/Python/context.c:727:29 (python3.15t+0x480a91)\n    #16 method_vectorcall_FASTCALL_KEYWORDS /cpython/Objects/descrobject.c:421:24 (python3.15t+0x229fe7) \n    #17 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x20fc33) \n    #18 PyObject_Vectorcall /cpython/Objects/call.c:327:12 (python3.15t+0x20fc33)\n    #19 _Py_VectorCallInstrumentation_StackRefSteal /cpython/Python/ceval.c:775:11 (python3.15t+0x42928c) \n    #20 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:1841:35 (python3.15t+0x42f07c) \n    #21 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x428660) \n    #22 _PyEval_Vector /cpython/Python/ceval.c:2124:12 (python3.15t+0x428660)\n    #23 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x2102af) \n    #24 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x211de9) \n    #25 _PyObject_VectorcallPrepend /cpython/Objects/call.c:855:20 (python3.15t+0x211de9)\n    #26 method_vectorcall /cpython/Objects/classobject.c:55:12 (python3.15t+0x21531f) \n    #27 _PyVectorcall_Call /cpython/Objects/call.c:273:16 (python3.15t+0x20ff3b) \n    #28 _PyObject_Call /cpython/Objects/call.c:348:16 (python3.15t+0x20ff3b)\n    #29 PyObject_Call /cpython/Objects/call.c:373:12 (python3.15t+0x20ffa5) \n    #30 thread_run /cpython/./Modules/_threadmodule.c:388:21 (python3.15t+0x605bc2) \n    #31 pythread_wrapper /cpython/Python/thread_pthread.h:234:5 (python3.15t+0x535427) \n\n  Location is global '_PyRuntime' of size 405120 at 0x555555e108c0 (python3.15t+0x8e4f80)\n```\n\n\n\n\n\n### CPython versions tested on:\n\nPython 3.15.0a8+ free-threading build (heads/main:44f1b987ed1, Apr 14 2026, 07:56:49)\n\n### Operating systems tested on:\n\nUbuntu\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-150356\n* gh-150841\n* gh-150842\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Naserume","@type":"Person","name":"Naserume"},"datePublished":"2026-04-15T12:41:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/148613/cpython/issues/148613"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f86ab030-6f65-eab5-77b5-1042b7e5709d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD6BC:1DE3C:37C1A:4B156:6A57AA68
html-safe-noncee38ee3a0a2665a461a4c27e9343ceef21d84102ad0e1b3a6a507077689407282
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkJDOjFERTNDOjM3QzFBOjRCMTU2OjZBNTdBQTY4IiwidmlzaXRvcl9pZCI6IjIwMDcxODAyODgxMzMxNDcyNDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacd005813e92ed036e478d4f75b2656509afd16190e436dc58ae69dd5dcb22364d
hovercard-subject-tagissue:4268976994
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/148613/issue_layout
twitter:imagehttps://opengraph.githubassets.com/949a0c19d7d31c907782fcd48c8558c9bc159e8c00f0c1302cabaebde7893de7/python/cpython/issues/148613
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/949a0c19d7d31c907782fcd48c8558c9bc159e8c00f0c1302cabaebde7893de7/python/cpython/issues/148613
og:image:altBug report Bug description: gc_set_threshold_impl writes gcstate->young.threshold cpython/Modules/gcmodule.c Lines 154 to 161 in 69e0a78 static PyObject * gc_set_threshold_impl(PyObject *module, in...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameNaserume
hostnamegithub.com
expected-hostnamegithub.com
None017a07c29bdd8a37b5907fc9a689338deb7103b5af7f56714193b2700229b3df
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
release4cd16a676f89d1cedb932671a5c2d20b8e60f86a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/148613#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F148613
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
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
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
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/enterprise/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%2F148613
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/148613
Reloadhttps://github.com/python/cpython/issues/148613
Reloadhttps://github.com/python/cpython/issues/148613
Please reload this pagehttps://github.com/python/cpython/issues/148613
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/148613
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k 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.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
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 and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Data race between gc_should_collect and gc_set_threshold_implhttps://github.com/python/cpython/issues/148613#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/Naserume
Naserumehttps://github.com/Naserume
on Apr 15, 2026https://github.com/python/cpython/issues/148613#issue-4268976994
cpython/Modules/gcmodule.chttps://github.com/python/cpython/blob/69e0a78e6edc3166c7a5b166955c0cefd1bacd5d/Modules/gcmodule.c#L154-L161
69e0a78https://github.com/python/cpython/commit/69e0a78e6edc3166c7a5b166955c0cefd1bacd5d
cpython/Python/gc_free_threading.chttps://github.com/python/cpython/blob/69e0a78e6edc3166c7a5b166955c0cefd1bacd5d/Python/gc_free_threading.c#L2198-L2203
69e0a78https://github.com/python/cpython/commit/69e0a78e6edc3166c7a5b166955c0cefd1bacd5d
gh-148613: Fix race in gc_set_threshold and gc_get_threshold #150356https://github.com/python/cpython/pull/150356
[3.15] gh-148613: Fix race in gc_set_threshold and gc_get_threshold (GH-150356) #150841https://github.com/python/cpython/pull/150841
[3.14] gh-148613: Fix race in gc_set_threshold and gc_get_threshold (GH-150356) #150842https://github.com/python/cpython/pull/150842
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%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.