From 6a2ac073bd74574836f5f48b7d0a20c57c9b2580 Mon Sep 17 00:00:00 2001
From: Greg Burd <greg@burd.me>
Date: Fri, 13 Nov 2026 08:58:08 -0500
Subject: [PATCH v4 08/21] port: Use the native Windows mapping of pg_threads.h
 with MSVC too.

pg_threads.h picked Visual Studio's <threads.h> for MSVC builds and
the native <windows.h> mapping for MinGW.  That gives Windows two
production implementations to keep in agreement, and makes MSVC
builds depend on vcruntime140_threads.dll, which the Visual C++
redistributable has to supply wherever PostgreSQL is installed.  It
saves MinGW nothing either: its binaries load libwinpthread-1.dll
anyway, through the gcc runtime.

Use the native mapping on all Windows builds.  <threads.h> stays
available with PG_THREADS_USE_THREADS_H, as on POSIX systems, to
check that pg_threads.h follows the standard.
---
 src/include/port/pg_threads.h                 | 11 +++++------
 src/include/port/pg_threads/map_threads_ext.h |  5 ++---
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/include/port/pg_threads.h b/src/include/port/pg_threads.h
index 5fe273d9625..561efba34a3 100644
--- a/src/include/port/pg_threads.h
+++ b/src/include/port/pg_threads.h
@@ -16,12 +16,13 @@
  * Three implementations are available:
  *
  * (1) map_pthread.h for <pthread.h> on POSIX systems
- * (2) map_threads.h for <threads.h> on Windows + Visual Studio
+ * (2) map_threads.h for <threads.h>
  * (3) map_windows.h for <windows.h> on Windows
  *
- * The choice is made automatically, but can be overridden for testing.
- * PG_THREADS_USE_THREADS_H works on common POSIX systems, but such builds are
- * intended strictly for testing (see map_threads_ext.h for details).
+ * The choice is made automatically, but can be overridden for testing.  (2)
+ * is never chosen automatically: it works with Visual Studio's <threads.h>
+ * and on common POSIX systems, but serves to check that pg_threads.h follows
+ * <threads.h> exactly (see map_threads_ext.h for details).
  *
  * The following macros are defined to signal known failures to conform to the
  * <threads.h> specification on some systems.  See the implementation headers
@@ -51,8 +52,6 @@
 	!defined(PG_THREADS_USE_WINDOWS_H)
 #if !defined(WIN32)
 #define PG_THREADS_USE_PTHREAD_H
-#elif defined(_MSC_VER)
-#define PG_THREADS_USE_THREADS_H
 #else
 #define PG_THREADS_USE_WINDOWS_H
 #endif
diff --git a/src/include/port/pg_threads/map_threads_ext.h b/src/include/port/pg_threads/map_threads_ext.h
index b13f0407b11..695f215de68 100644
--- a/src/include/port/pg_threads/map_threads_ext.h
+++ b/src/include/port/pg_threads/map_threads_ext.h
@@ -28,9 +28,8 @@
 
 #if defined(WIN32)
 /*
- * Visual Studio's <thread.h>: cnd_t and mtx_t can be zero-initialized per
- * published documentation and example code, so this is a supported deployment
- * configuration.
+ * Visual Studio's <threads.h>: cnd_t and mtx_t can be zero-initialized per
+ * published documentation and example code.
  */
 #define PG_CND_INIT_IMPL			{0}
 #define PG_MTX_PLAIN_INIT_IMPL		{0}
-- 
2.54.0

