Windows ECPG pthread_once publication ordering

From: Harrison Booth <harrisontbooth(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Windows ECPG pthread_once publication ordering
Date: 2026-10-13 01:34:00
Message-ID: CAAH-eSWq9UTbFhHrzq0T8U0J2qCaiprLw93F5qB20=GUHg1ocQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Attached is a separate Windows ECPG pthread_once ordering fix that
keeps pthread_once_t as bool and preserves the exported helper
signature.

The public macro currently reads the bool without acquire ordering and
can bypass the helper entirely. A source-extracted two-thread stress
test on native ARM64 observes the initialized flag before callback
data is visible. It preinitializes the mutex to isolate this from the
separate mutex initialization issue. Saved baseline runs fail under
both /volatile:iso and /volatile:ms, since the latter doesn't make the
macro's ordinary bool read volatile.

The patch uses acquire reads in the macro and both helper checks, then
release publication after the callback. MSVC ARM64 uses the SDK byte
acquire/release operations. MSVC x86/x64 adds compiler barriers for
/volatile:iso; GNU uses atomic builtins. The compiler barrier is
deprecated, so feedback on that choice would be useful.

The exact candidate passes 4 million initializations and 8 million
checks per configuration on ARM64 /volatile:iso, x64 /volatile:iso and
/volatile:ms, and MinGW GCC 13.2 x64. C/C++ header checks pass. Full
ECPG suites pass all 66 subtests on native ARM64 and emulated x64,
with the separate mutex and Meson patches in the integration checkout.
This is standalone red/green evidence, not a reproduced complete ECPG
query failure.

The patch is based on master 8e82d6610e7 and applies cleanly to the
checked REL_17/18/19_STABLE heads; those branches weren't built.
pgindent checks pass.

Let me know your thoughts.

Best,

Harrison

Attachment Content-Type Size
0001-Fix-Windows-ECPG-pthread_once-publication-ordering.patch text/x-diff 3.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Chee Wooson 2026-10-13 01:47:54 Re: Re: [PATCH] Discard aborted updaters when expanding a multixact
Previous Message Harrison Booth 2026-10-13 01:33:56 Re: Windows locales and tests portability