Win32 Thread safetyness - Mailing list pgsql-hackers

From Dave Page
Subject Win32 Thread safetyness
Date
Msg-id E7F85A1B5FF8D44C8A1AF6885BC9A0E4AC9C52@ratbert.vale-housing.co.uk
Whole thread Raw
Responses Re: Win32 Thread safetyness  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
Unfortunately I just found that we still cannot build in thread safety
mode on Windows, due to an error on my part - specifically, I
concentrated on libpq, not realising that ecpglib is also thread aware.

It seems that ecpglib uses far more of pthreads than libpq does, so our
mini implementation used in libpq just won't cut it. I've bitten the
bullet (well, more of a jelly bean actually) and started rewriting
things to use the official win32 pthreads library, however I ran into an
error that I'm not sure about:

make[3]: Entering directory `/cvs/pgsql/src/interfaces/libpq'
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wold-style-definition -Wendif-labels
-fno-strict-aliasing -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS  -DFRONTEND -I. -I../../../src/include
-I./src/include/port/win32 -DEXEC_BACKEND
"-I../../../src/include/port/win32" -I../../../src/port  -c -o
fe-secure.o fe-secure.c
fe-secure.c: In function `pq_threadidcallback':
fe-secure.c:879: error: aggregate value used where an integer was
expected

Which relates to:

static unsigned long
pq_threadidcallback(void)
{   return (unsigned long) pthread_self();
}

In pthread.h we have:

typedef struct {   void * p;                   /* Pointer to actual object */   unsigned int x;             /* Extra
information- reuse count etc 
*/
} ptw32_handle_t;

typedef ptw32_handle_t pthread_t;

PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void);

Is it enough just to pass p back on Windows? - eg:

static unsigned long
pq_threadidcallback(void)
{
#ifdef WIN32return (unsigned long) pthread_self().p;
#elsereturn (unsigned long) pthread_self();
#endif
}

Everything builds OK with this change - I'm just not sure if it's right.

Regards, Dave


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: [PATCHES] Proposed patch to getaddrinfo.c to support
Next
From: "Jim Nasby"
Date:
Subject: Re: TODO questions