Index: fe-connect.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.357
diff -c -r1.357 fe-connect.c
*** fe-connect.c	31 Mar 2008 02:43:14 -0000	1.357
--- fe-connect.c	21 Apr 2008 11:35:33 -0000
***************
*** 3827,3841 ****
  #ifndef WIN32
  	static pthread_mutex_t singlethread_lock = PTHREAD_MUTEX_INITIALIZER;
  #else
! 	static pthread_mutex_t singlethread_lock = NULL;
  	static long mutex_initlock = 0;
  
! 	if (singlethread_lock == NULL)
  	{
  		while (InterlockedExchange(&mutex_initlock, 1) == 1)
! 			 /* loop, another thread own the lock */ ;
! 		if (singlethread_lock == NULL)
  			pthread_mutex_init(&singlethread_lock, NULL);
  		InterlockedExchange(&mutex_initlock, 0);
  	}
  #endif
--- 3827,3845 ----
  #ifndef WIN32
  	static pthread_mutex_t singlethread_lock = PTHREAD_MUTEX_INITIALIZER;
  #else
! 	static pthread_mutex_t singlethread_lock;
! 	static bool initialized = false;
  	static long mutex_initlock = 0;
  
! 	if (!initialized)
  	{
  		while (InterlockedExchange(&mutex_initlock, 1) == 1)
! 			/* loop, another thread own the lock */ ;
! 		if (!initialized)
! 		{
  			pthread_mutex_init(&singlethread_lock, NULL);
+ 			initialized = true;
+ 		}
  		InterlockedExchange(&mutex_initlock, 0);
  	}
  #endif
Index: fe-secure.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v
retrieving revision 1.104
diff -c -r1.104 fe-secure.c
*** fe-secure.c	31 Mar 2008 02:43:14 -0000	1.104
--- fe-secure.c	21 Apr 2008 11:44:22 -0000
***************
*** 809,823 ****
  #ifndef WIN32
  	static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
  #else
! 	static pthread_mutex_t init_mutex = NULL;
  	static long mutex_initlock = 0;
  
! 	if (init_mutex == NULL)
  	{
  		while (InterlockedExchange(&mutex_initlock, 1) == 1)
  			 /* loop, another thread own the lock */ ;
! 		if (init_mutex == NULL)
  			pthread_mutex_init(&init_mutex, NULL);
  		InterlockedExchange(&mutex_initlock, 0);
  	}
  #endif
--- 809,827 ----
  #ifndef WIN32
  	static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
  #else
! 	static pthread_mutex_t init_mutex;
! 	static bool initialized = false;
  	static long mutex_initlock = 0;
  
! 	if (!initialized)
  	{
  		while (InterlockedExchange(&mutex_initlock, 1) == 1)
  			 /* loop, another thread own the lock */ ;
! 		if (!initialized)
! 		{
  			pthread_mutex_init(&init_mutex, NULL);
+ 			initialized = true;
+ 		}
  		InterlockedExchange(&mutex_initlock, 0);
  	}
  #endif
Index: pthread-win32.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/pthread-win32.c,v
retrieving revision 1.15
diff -c -r1.15 pthread-win32.c
*** pthread-win32.c	1 Jan 2008 19:46:00 -0000	1.15
--- pthread-win32.c	21 Apr 2008 11:27:38 -0000
***************
*** 35,51 ****
  void
  pthread_mutex_init(pthread_mutex_t *mp, void *attr)
  {
! 	*mp = CreateMutex(0, 0, 0);
  }
  
  void
  pthread_mutex_lock(pthread_mutex_t *mp)
  {
! 	WaitForSingleObject(*mp, INFINITE);
  }
  
  void
  pthread_mutex_unlock(pthread_mutex_t *mp)
  {
! 	ReleaseMutex(*mp);
  }
--- 35,51 ----
  void
  pthread_mutex_init(pthread_mutex_t *mp, void *attr)
  {
! 	InitializeCriticalSection(mp);
  }
  
  void
  pthread_mutex_lock(pthread_mutex_t *mp)
  {
! 	EnterCriticalSection(mp);
  }
  
  void
  pthread_mutex_unlock(pthread_mutex_t *mp)
  {
! 	LeaveCriticalSection(mp);
  }
