diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-10-24 13:12:08 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-10-24 13:12:08 -0400 |
commit | 21d36747d4fafe16539a0c55ebb91a01e4053e3c (patch) | |
tree | 86d81c043d22e3db0d454ca4e03bdc196bbe9f9f | |
parent | 2771fcee18be0b86d2e008add20f73d175e06e90 (diff) | |
download | postgresql-21d36747d4fafe16539a0c55ebb91a01e4053e3c.tar.gz postgresql-21d36747d4fafe16539a0c55ebb91a01e4053e3c.zip |
Fix ancient bug in ecpg's pthread_once() emulation for Windows.
We must not set the "done" flag until after we've executed the
initialization function. Otherwise, other threads can fall through
the initial unlocked test before initialization is really complete.
This has been seen to cause rare failures of ecpg's thread/descriptor
test, and it could presumably cause other sorts of misbehavior in
threaded ECPG-using applications, since ecpglib relies on
pthread_once() in several places.
Diagnosis and patch by me, based on investigation by Alexander Lakhin.
Back-patch to all supported branches (the bug dates to 2007).
Discussion: https://postgr.es/m/16685-d6cd241872c101d3@postgresql.org
-rw-r--r-- | src/interfaces/ecpg/ecpglib/misc.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index a07d0dfb9fc..1feb5c03e17 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -477,8 +477,8 @@ win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void)) pthread_mutex_lock(&win32_pthread_once_lock); if (!*once) { - *once = true; fn(); + *once = true; } pthread_mutex_unlock(&win32_pthread_once_lock); } |