| From: | harrisontbooth(at)gmail(dot)com |
|---|---|
| To: | Alexander Lakhin <exclusion(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: [PATCH v2] Fix races in Windows pthread emulation |
| Date: | 2026-10-12 23:37:27 |
| Message-ID: | CAAH-eSUuw3SMTbGXpD7opQe-QFjKpQPK73UUpU3J_ReczQph=Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Attached is a mutex-only v2 rebased on master at 8e82d6610e7. It
leaves pthread_once and the existing type layouts unchanged.
Only a thread that claims state 0 initializes the critical section and
publishes state 1. The lock fast path uses an acquire load instead of
an interlocked read-modify-write; unlock uses a relaxed load after a
successful lock.
The deterministic reproducer returns EINVAL on the original code and
passes with v2. Stress testing passed 800,000 lock/unlock pairs per
configuration on native ARM64 MSVC, emulated x64 MSVC, and emulated
x64 MinGW.
Full ARM64 and x64 builds passed. On each architecture, ECPG passed 66
subtests, libpq passed 241, and pg_basebackup passed 151. The ARM64
ECPG rerun passed after adding the missing diff tool to PATH.
The patch applies cleanly to REL_17_STABLE and REL_18_STABLE; neither
stable branch was built.
Alexander, could you test this revision against your reproducer?
Heikki, do the acquire loads and separate pthread_once work address
your concerns?
A separate GitHub-hosted Windows x64 build and all nine test groups
passed with all three patches applied. ECPG passed 66 subtests, libpq
passed 241, and pg_basebackup passed 152.
Best,
Harrison
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fix-races-in-Windows-pthread-mutex-initialization.patch | text/x-diff | 3.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | harrisontbooth | 2026-10-12 23:37:29 | Re: [PATCH v3] Fix pg_basebackup long-path test on Windows |
| Previous Message | shihao zhong | 2026-10-12 23:33:33 | Re: [Patch] New pg_stat_tablespace view |