Title: Race in stgdict PyCStructUnionType_update_stginfo under free-threading · Issue #128570 · python/cpython · GitHub
Open Graph Title: Race in stgdict PyCStructUnionType_update_stginfo under free-threading · Issue #128570 · python/cpython
X Title: Race in stgdict PyCStructUnionType_update_stginfo under free-threading · Issue #128570 · python/cpython
Description: Bug report Bug description: I built cpython (3.13 branch) with free-threading and TSAN. The following python code reports TSAN warnings: import ctypes import concurrent.futures import threading def make_nd_memref_descriptor(rank, dtype):...
Open Graph Description: Bug report Bug description: I built cpython (3.13 branch) with free-threading and TSAN. The following python code reports TSAN warnings: import ctypes import concurrent.futures import threading def...
X Description: Bug report Bug description: I built cpython (3.13 branch) with free-threading and TSAN. The following python code reports TSAN warnings: import ctypes import concurrent.futures import threading def...
Opengraph URL: https://github.com/python/cpython/issues/128570
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Race in stgdict PyCStructUnionType_update_stginfo under free-threading","articleBody":"# Bug report\n\n### Bug description:\n\nI built cpython (3.13 branch) with free-threading and TSAN. The following python code reports TSAN warnings:\n```python\nimport ctypes\nimport concurrent.futures\nimport threading\n\n\ndef make_nd_memref_descriptor(rank, dtype):\n class MemRefDescriptor(ctypes.Structure):\n _fields_ = [\n (\"aligned\", ctypes.POINTER(dtype)),\n ]\n\n return MemRefDescriptor\n\n\nclass F32(ctypes.Structure):\n _fields_ = [(\"f32\", ctypes.c_float)]\n\n\ndef test_ctypes():\n arg1_ndim = 1\n ctp = F32\n ctypes.pointer(\n ctypes.pointer(make_nd_memref_descriptor(arg1_ndim, ctp)())\n )\n\n\nif __name__ == \"__main__\":\n num_workers = 20\n\n barrier = threading.Barrier(num_workers)\n\n def closure():\n barrier.wait()\n test_ctypes()\n\n with concurrent.futures.ThreadPoolExecutor(max_workers=num_workers) as executor:\n futures = []\n for i in range(num_workers):\n futures.append(executor.submit(closure))\n assert len(list(f.result() for f in futures)) == num_workers\n\n```\nTSAN report extract:\n```\nWARNING: ThreadSanitizer: data race (pid=264065)\n Read of size 4 at 0x7fffb80a0430 by thread T17:\n #0 PyCStructUnionType_update_stginfo /project/cpython/./Modules/_ctypes/stgdict.c:438:19 (_ctypes.cpython-313t-x86_64-linux-gnu.so+0x20976) (BuildId: 6a7727f376cee83a3124898fe6eb84e45e3a54bc)\n #1 PyCStructType_setattro /project/cpython/./Modules/_ctypes/_ctypes.c:1096:16 (_ctypes.cpython-313t-x86_64-linux-gnu.so+0xc809) (BuildId: 6a7727f376cee83a3124898fe6eb84e45e3a54bc)\n #2 PyObject_SetAttr /project/cpython/Objects/object.c:1415:15 (python3.13t+0x294fba) (BuildId: 65e52348ca9319985f9f5e265fd43aab2c867d59)\n #3 StructUnionType_init /project/cpython/./Modules/_ctypes/_ctypes.c:685:13 (_ctypes.cpython-313t-x86_64-linux-gnu.so+0xe222) (BuildId: 6a7727f376cee83a3124898fe6eb84e45e3a54bc)\n #4 PyCStructType_init /project/cpython/./Modules/_ctypes/_ctypes.c:715:12 (_ctypes.cpython-313t-x86_64-linux-gnu.so+0xc84a) (BuildId: 6a7727f376cee83a3124898fe6eb84e45e3a54bc)\n\n```\n\n[Full traceback](https://gist.github.com/vfdev-5/450dddf763d1ef9039c4385722cf797c)\n\n\nRelated to https://github.com/python/cpython/issues/127945\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nLinux","author":{"url":"https://github.com/vfdev-5","@type":"Person","name":"vfdev-5"},"datePublished":"2025-01-07T02:13:49Z","url":"https://github.com/python/cpython/issues/128570"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:de6a1505-2ff8-ab8a-d72c-4066b07432df |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A1A6:291B58:359EB62:43F6F10:6B021B3A |
| html-safe-nonce | 174b8d7fabe253ee472b8214b4d29315940f4358a48d85518ed62f4cc6f9b5a7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUE2OjI5MUI1ODozNTlFQjYyOjQzRjZGMTA6NkIwMjFCM0EiLCJ2aXNpdG9yX2lkIjoiNTI1MzM1NTYwNzQxODg3MDU4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1a7e4992d3e8d04c94603e23d16379cf208da8022b9150dad9683cead032d033 |
| hovercard-subject-tag | issue:2771753174 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/128570/issue_layout |
| twitter:image | https://opengraph.githubassets.com/036bbc218f5395d180bbc3abe51e555be2bcb164bca785864049d7ba6b760df0/python/cpython/issues/128570 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/036bbc218f5395d180bbc3abe51e555be2bcb164bca785864049d7ba6b760df0/python/cpython/issues/128570 |
| og:image:alt | Bug report Bug description: I built cpython (3.13 branch) with free-threading and TSAN. The following python code reports TSAN warnings: import ctypes import concurrent.futures import threading def... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vfdev-5 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width