pgsql: Clean up thread management in parallel pg_dump for Windows.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Clean up thread management in parallel pg_dump for Windows.
Date: 2016-05-27 16:02:24
Message-ID: E1b6KDQ-0000Xp-KP@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Clean up thread management in parallel pg_dump for Windows.

Since we start the worker threads with _beginthreadex(), we should use
_endthreadex() to terminate them. We got this right in the normal-exit
code path, but not so much during an error exit from a worker.
In addition, be sure to apply CloseHandle to the thread handle after
each thread exits.

It's not clear that these oversights cause any user-visible problems,
since the pg_dump run is about to terminate anyway. Still, it's clearly
better to follow Microsoft's API specifications than ignore them.

Also a few cosmetic cleanups in WaitForTerminatingWorkers(), including
being a bit less random about where to cast between uintptr_t and HANDLE,
and being sure to clear the worker identity field for each dead worker
(not that false matches should be possible later, but let's be careful).

Original observation and patch by Armin Schöffmann, cosmetic improvements
by Michael Paquier and me. (Armin's patch also included closing sockets
in ShutdownWorkersHard(), but that's been dealt with already in commit
df8d2d8c4.) Back-patch to 9.3 where parallel pg_dump was introduced.

Discussion: <zarafa(dot)570306bd(dot)3418(dot)074bf1420d8f2ba2(at)root(dot)aegaeon(dot)de>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/807b45375beae6563c3833e72d91869e9b9134e5

Modified Files
--------------
src/bin/pg_dump/parallel.c | 53 ++++++++++++++++++++++++++-------------
src/bin/pg_dump/pg_backup_utils.c | 2 +-
2 files changed, 37 insertions(+), 18 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2016-05-28 18:02:45 pgsql: Lots of comment-fixing, and minor cosmetic cleanup, in pg_dump/p
Previous Message Kevin Grittner 2016-05-27 15:35:37 Re: [HACKERS] Re: pgsql: Avoid extra locks in GetSnapshotData if old_snapshot_threshold <