Fix ancient bug in ecpg's pthread_once() emulation for Windows.
authorTom Lane <[email protected]>
Sat, 24 Oct 2020 17:12:08 +0000 (13:12 -0400)
committerTom Lane <[email protected]>
Sat, 24 Oct 2020 17:12:53 +0000 (13:12 -0400)
commit758b45e83b50b08a0bca03a9b5610a27ed7c7b09
tree248901ca295bebcfa7b85e1fdc96e3b90e57bb2f
parent0abebb58f522b190b208c31e704b60ea5b6f0a28
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