Trying out <stdatomic.h>

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Trying out <stdatomic.h>
Date: 2025-11-10 13:17:31
Message-ID: CA+hUKGKFvu3zyvv3aaj5hHs9VtWcjFAmisOwOc7aOZNc5AF3NA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

Attachment Content-Type Size
v1-0001-Add-some-missing-include-limits.h.patch application/octet-stream 1.7 KB
v1-0002-Redefine-port-atomics.h-on-top-of-stdatomic.h.patch application/octet-stream 67.9 KB
v1-0003-Use-atomics-API-to-implement-spinlocks.patch application/octet-stream 36.2 KB
v1-0004-Remove-configure-meson-checks-for-atomics.patch application/octet-stream 16.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Manni Wood 2025-11-10 13:47:01 Re: [PATCH] Add pg_get_tablespace_ddl() function to reconstruct CREATE TABLESPACE statement
Previous Message Tim Waizenegger 2025-11-10 12:44:36 Re: [PATCH] pg_get_domain_ddl: DDL reconstruction function for CREATE DOMAIN statement