Title: Race in ctypes PyCFuncPtr_new under free-threading · Issue #128567 · python/cpython · GitHub
Open Graph Title: Race in ctypes PyCFuncPtr_new under free-threading · Issue #128567 · python/cpython
X Title: Race in ctypes PyCFuncPtr_new under free-threading · Issue #128567 · 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 raw_func(x): pass def test_ctypes(): de...
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/128567
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Race in ctypes PyCFuncPtr_new under free-threading ","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nI built cpython (3.13 branch) with free-threading and TSAN. The following python code reports TSAN warnings:\r\n```python\r\nimport ctypes\r\nimport concurrent.futures\r\nimport threading\r\n\r\n\r\ndef raw_func(x):\r\n pass\r\n\r\n\r\ndef test_ctypes():\r\n def lookup():\r\n prototype = ctypes.CFUNCTYPE(None, ctypes.c_void_p)\r\n return prototype(raw_func)\r\n\r\n ctypes_args = ()\r\n func = lookup()\r\n packed_args = (ctypes.c_void_p * len(ctypes_args))()\r\n for argNum in range(len(ctypes_args)):\r\n packed_args[argNum] = ctypes.cast(ctypes_args[argNum], ctypes.c_void_p)\r\n func(packed_args)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n num_workers = 20\r\n\r\n barrier = threading.Barrier(num_workers)\r\n\r\n def closure():\r\n barrier.wait()\r\n test_ctypes()\r\n\r\n with concurrent.futures.ThreadPoolExecutor(max_workers=num_workers) as executor:\r\n futures = []\r\n for i in range(num_workers):\r\n futures.append(executor.submit(closure))\r\n assert len(list(f.result() for f in futures)) == num_workers\r\n\r\n```\r\nTSAN report extract:\r\n```\r\nWARNING: ThreadSanitizer: data race (pid=261974)\r\n Write of size 4 at 0x7fffbe0d0430 by thread T5:\r\n #0 generic_pycdata_new /project/cpython/./Modules/_ctypes/_ctypes.c:3387:17 (_ctypes.cpython-313t-x86_64-linux-gnu.so+0xdbb7) (BuildId: 6a7727f376cee83a3124898fe6eb84e45e3a54bc)\r\n #1 PyCFuncPtr_new /project/cpython/./Modules/_ctypes/_ctypes.c:3963:32 (_ctypes.cpython-313t-x86_64-linux-gnu.so+0x18bbb) (BuildId: 6a7727f376cee83a3124898fe6eb84e45e3a54bc)\r\n #2 type_call /project/cpython/Objects/typeobject.c:1981:11 (python3.13t+0x2eb032) (BuildId: 65e52348ca9319985f9f5e265fd43aab2c867d59)\r\n #3 _PyObject_MakeTpCall /project/cpython/Objects/call.c:242:18 (python3.13t+0x1ea44c) (BuildId: 65e52348ca9319985f9f5e265fd43aab2c867d59)\r\n #4 _PyObject_VectorcallTstate /project/cpython/./Include/internal/pycore_call.h:166:16 (python3.13t+0x1eb0a8) (BuildId: 65e52348ca9319985f9f5e265fd43aab2c867d59)\r\n #5 PyObject_Vectorcall /project/cpython/Objects/call.c:327:12 (python3.13t+0x1eb0a8)\r\n```\r\n\r\n[Full traceback](https://gist.github.com/vfdev-5/94ac799fddf453dc8d7186024861ccb7)\r\n \r\n\r\nRelated https://github.com/python/cpython/issues/128182\r\n\r\n\r\n\r\n### CPython versions tested on:\r\n\r\n3.13\r\n\r\n### Operating systems tested on:\r\n\r\nLinux","author":{"url":"https://github.com/vfdev-5","@type":"Person","name":"vfdev-5"},"datePublished":"2025-01-07T01:31:43Z","url":"https://github.com/python/cpython/issues/128567"}
| 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:fd67c8ab-5317-1eee-f230-dcb726478339 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D16A:14EB6E:1BDA60A:248E494:6B021B62 |
| html-safe-nonce | 4df57e4a2a1c69df05fc65ff549982eeb26a695925634c6cffff2a5ade52ecda |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTZBOjE0RUI2RToxQkRBNjBBOjI0OEU0OTQ6NkIwMjFCNjIiLCJ2aXNpdG9yX2lkIjoiNzkwMzc1OTUyNzE4OTM0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | eb187daa32ac02fa0c9782923601e8797621dc69a325ea6dd4bad4ee520f9a91 |
| hovercard-subject-tag | issue:2771719080 |
| 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/128567/issue_layout |
| twitter:image | https://opengraph.githubassets.com/036bbc218f5395d180bbc3abe51e555be2bcb164bca785864049d7ba6b760df0/python/cpython/issues/128567 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/036bbc218f5395d180bbc3abe51e555be2bcb164bca785864049d7ba6b760df0/python/cpython/issues/128567 |
| 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