On Wed, Jun 4, 2025 at 2:02 AM Tom Lane <t...@sss.pgh.pa.us> wrote: > Yura Sokolov <y.soko...@postgrespro.ru> writes: > > Will it mean we can implement atomics in term of C11 atomics? > > Any such change would have to be supported by extensive performance > testing to verify that there's not a regression on any supported > platform. Yeah, it'd be cool if we could rip out a lot of that > code, but we aren't going to just rip on faith.
FWIW I posted an experimental patch like that at: https://www.postgresql.org/message-id/flat/CA%2BhUKG%2Bw-2RyyYUte_mSAunoRE00bQUCG44%3DFiOuyMaN-6uoOw%40mail.gmail.com#60354fbd9784c58d3eeaf9a4193a7414 To make progress down this path, yeah, we'd definitely want to do a bunch of cross-platform evaluation work, ie performance valuation and probably reading assembler. Note that in that experiment I just mapped to the non-_explicit() variants (in other words all the operations are defaulting to memory_order_seq_cst, which is too strong in many cases), so we'd also what to think hard about which of the pg_atomics operations should use _explicit() with a weaker memory_order. Nearby there are also patches to change our spinlocks to use pg_atomics, so then that just becomes standard C11 code too. Assuming all that can be ironed out, AFAIK there is only one piece that we'll still need to hand-roll, because C11 doesn't provide anything like it: pg_spin_delay_impl(). (I haven't looked into whether there is anything standard proposed to deal with that in some future C.)