[Patch] Use internal pthreads reimplementation only when building with MSVC

Started by Sandro Maniover 6 years ago4 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t42193
psql -h localhost -U postgres

Built from patchset v3 (message #3), July 27, 2026 at 06:58 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t42193_3 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t42193_3 && git checkout t42193_3

Patchset v3 (message #3) is on t42193_3

Jump to latest
#1Sandro Mani
manisandro@gmail.com

Hi

The following patch, which we added to build mingw-postgresql on Fedora,
makes the internal minimal pthreads reimplementation only used when
building with MSVC, as on MINGW it causes symbol collisions with the
symbols provided my winpthreads.

Thanks
Sandro

diff -rupN postgresql-11.5/src/interfaces/ecpg/ecpglib/misc.c 
postgresql-11.5-new/src/interfaces/ecpg/ecpglib/misc.c
--- postgresql-11.5/src/interfaces/ecpg/ecpglib/misc.c 2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/ecpg/ecpglib/misc.c 2020-04-08 
11:20:39.850738296 +0200
@@ -449,7 +449,7 @@ ECPGis_noind_null(enum ECPGttype type, c
      return false;
  }
-#ifdef WIN32
+#ifdef _MSC_VER
  #ifdef ENABLE_THREAD_SAFETY
  void
diff -rupN 
postgresql-11.5/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
postgresql-11.5-new/src/interfaces/ecpg/include/ecpg-pthread-win32.h
--- postgresql-11.5/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
2019-08-05 23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
2020-04-08 11:20:39.851738296 +0200
@@ -7,7 +7,7 @@

 #ifdef ENABLE_THREAD_SAFETY

-#ifndef WIN32
+#ifndef _MSC_VER
  #include <pthread.h>
  #else
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-connect.c 
postgresql-11.5-new/src/interfaces/libpq/fe-connect.c
--- postgresql-11.5/src/interfaces/libpq/fe-connect.c 2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-connect.c 2020-04-08 
11:20:39.853738297 +0200
@@ -50,7 +50,7 @@
  #endif
  #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
  #include "pthread-win32.h"
  #else
  #include <pthread.h>
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-secure.c 
postgresql-11.5-new/src/interfaces/libpq/fe-secure.c
--- postgresql-11.5/src/interfaces/libpq/fe-secure.c    2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-secure.c 2020-04-08 
11:20:39.854738297 +0200
@@ -48,7 +48,7 @@
  #include <sys/stat.h>
  #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
  #include "pthread-win32.h"
  #else
  #include <pthread.h>
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-secure-openssl.c 
postgresql-11.5-new/src/interfaces/libpq/fe-secure-openssl.c
--- postgresql-11.5/src/interfaces/libpq/fe-secure-openssl.c 2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-secure-openssl.c 
2020-04-08 11:20:39.855738298 +0200
@@ -47,7 +47,7 @@
  #include <sys/stat.h>
  #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
  #include "pthread-win32.h"
  #else
  #include <pthread.h>
diff -rupN postgresql-11.5/src/interfaces/libpq/libpq-int.h 
postgresql-11.5-new/src/interfaces/libpq/libpq-int.h
--- postgresql-11.5/src/interfaces/libpq/libpq-int.h    2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/libpq-int.h 2020-04-08 
11:20:39.855738298 +0200
@@ -29,7 +29,7 @@
  #endif
  #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
  #include "pthread-win32.h"
  #else
  #include <pthread.h>
diff -rupN postgresql-11.5/src/interfaces/libpq/pthread-win32.c 
postgresql-11.5-new/src/interfaces/libpq/pthread-win32.c
--- postgresql-11.5/src/interfaces/libpq/pthread-win32.c 2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/pthread-win32.c 2020-04-08 
11:21:51.674766968 +0200
@@ -10,10 +10,13 @@
  *-------------------------------------------------------------------------
  */
+#ifdef _MSC_VER
+
  #include "postgres_fe.h"

 #include "pthread-win32.h"

+
 DWORD
 pthread_self(void)
 {
@@ -58,3 +61,5 @@ pthread_mutex_unlock(pthread_mutex_t *mp
     LeaveCriticalSection(*mp);
     return 0;
 }
+
+#endif // _MSC_VER

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Sandro Mani (#1)
Re: [Patch] Use internal pthreads reimplementation only when building with MSVC

Hello,

On 2020-Apr-08, Sandro Mani wrote:

The following patch, which we added to build mingw-postgresql on Fedora,
makes the internal minimal pthreads reimplementation only used when building
with MSVC, as on MINGW it causes symbol collisions with the symbols provided
my winpthreads.

Are there any build-system tweaks needed to enable use of winpthreads?
If none are needed, why are all our mingw buildfarm members building
correctly? I suggest that if you want to maintain "mingw-postgresql
built on Fedora", it would be a good idea to have a buildfarm animal
that tests it on a recurring basis.

Please do submit patches as separate attachments rather than in the
email body.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Alvaro Herrera (#2)
Re: [Patch] Use internal pthreads reimplementation only when building with MSVC

On 9 Apr 2020, at 23:57, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Please do submit patches as separate attachments rather than in the
email body.

Since the CF app is unable to see that there is a patch at all, I took the
liberty to resubmit the posted patch rebased on top of HEAD and with the C++
replaced with a C /* */ comment.

Marking this entry Waiting on Author based on Alvaros questions.

cheers ./daniel

Attachments:

t42193_3
msvc_pthreads.diffapplication/octet-stream; name=msvc_pthreads.diff; x-unix-mode=0644Download+11-6
#4Daniel Gustafsson
daniel@yesql.se
In reply to: Daniel Gustafsson (#3)
Re: [Patch] Use internal pthreads reimplementation only when building with MSVC

On 2 Jul 2020, at 16:35, Daniel Gustafsson <daniel@yesql.se> wrote:

On 9 Apr 2020, at 23:57, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Please do submit patches as separate attachments rather than in the
email body.

Since the CF app is unable to see that there is a patch at all, I took the
liberty to resubmit the posted patch rebased on top of HEAD and with the C++
replaced with a C /* */ comment.

This version now applies and builds but..

Marking this entry Waiting on Author based on Alvaros questions.

..since the thread has stalled with no response to review questions I'm marking
this Returned with Feedback.

cheers ./daniel