postgres.git / summary / log / commit / refs

commit    12a73f29ff7d00ea96ec4c5d1bef9acb5985d688
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Sat Oct 24 17:12:08 2020 +0000
First released in: 14.0, 9.5.24, 9.6.20, 10.15, 11.10, 12.5, 13.1

    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


src/interfaces/ecpg/ecpglib/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index be9cac6e7b4..85a308f5379 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -475,8 +475,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); } [parent: 02f86d52382c]