git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2771fce)
Fix ancient bug in ecpg's pthread_once() emulation for Windows.
2020年10月24日 17:12:08 +0000 (13:12 -0400)
2020年10月24日 17:12:08 +0000 (13:12 -0400)
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


diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index a07d0dfb9fc2a6b90ea2ac8ea5cccb5ed317ed37..1feb5c03e1749c7b9824a47be122e082b470bda2 100644 (file)
--- 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);
}
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /