Trying out <stdatomic.h>
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-11-10T13:17:31Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add some missing #include <limits.h>.
- 017249b82888 19 (unreleased) landed
-
Enable MSVC conforming preprocessor
- 8fd9bb1d9654 19 (unreleased) cited
Attachments
- v1-0001-Add-some-missing-include-limits.h.patch (application/octet-stream) patch v1-0001
- v1-0002-Redefine-port-atomics.h-on-top-of-stdatomic.h.patch (application/octet-stream) patch v1-0002
- v1-0003-Use-atomics-API-to-implement-spinlocks.patch (application/octet-stream) patch v1-0003
- v1-0004-Remove-configure-meson-checks-for-atomics.patch (application/octet-stream) patch v1-0004
Hi, Here is an experimental patch to try out standard C (and C++) atomics to implement port/atomics.h, and also add more types and operations. It's mostly just redirecting our names to the standard ones, except for our barriers and slightly extended pg_atomic_flag, so there isn't much left of the code. Here also is a semi-independent patch to implement storage/spin.h with pg_atomic_flag. It keeps a small amount of the architecture-specific magic, but moves it out to src/port/spin_delay.h. I'm not saying they're correct, performant or portable yet, that'll require studying codegen and performance on a bunch of weird and wonderful systems, but they at least passes basic testing on the usual suspects and CI systems, except for Windows which needs a newer toolchain so I haven't tried yet. It should hopefully just work™ on VS 2022 (same version that provides <threads.h>, about which more soon). All that being the case, it's not far enough along to be a serious proposal, but I imagine others will be looking into things like this since we pulled the trigger on C11 and I figured I might as well share a basic working patch set to avoid duplicated effort... Hopefully it works well enough to kick the tyres and try to find the difficult problems, test it out on weird systems, etc etc.