Re: Cleaning up threading code
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Peter Eisentraut <peter@eisentraut.org>,
Andres Freund <andres@anarazel.de>, Thomas Munro <thomas.munro@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2023-07-03T08:43:14Z
Lists: pgsql-hackers
Attachments
- update-libpq-thread-safety-docs.patch (text/x-patch) patch
On 03/07/2023 10:29, Peter Eisentraut wrote:
> On 10.06.23 07:26, Andres Freund wrote:
>>> -###############################################################
>>> -# Threading
>>> -###############################################################
>>> -
>>> -# XXX: About to rely on thread safety in the autoconf build, so not worth
>>> -# implementing a fallback.
>>> -cdata.set('ENABLE_THREAD_SAFETY', 1)
>>
>> I wonder if we should just unconditionally set that in c.h or such? It'd not
>> be crazy for external projects to rely on that being set.
>
> We definitely should keep the mention in ecpg_config.h.in, since that is
> explicitly put there for client code to use. We keep HAVE_LONG_LONG_INT
> etc. there for similar reasons.
+1. Patches 1-3 look good to me, with the things Andres & Peter already
pointed out.
The docs at https://www.postgresql.org/docs/current/libpq-threading.html
needs updating. It's technically still accurate, but it ought to at
least mention that libpq on v17 and above is always thread-safe. I
propose the attached. It moves the note on "you can only use one PGConn
from one thread at a time" to the top, before the description of the
PQisthreadsafe() function.
On 10/06/2023 05:23, Thomas Munro wrote:
>
> 2. I don't like the way we have to deal with POSIX vs Windows at
> every site where we use threads, and each place has a different style
> of wrappers. I considered a few different approaches to cleaning this
> up:
>
> * provide centralised and thorough pthread emulation for Windows; I
> don't like this, I don't even like all of pthreads and there are many
> details to get lost in
> * adopt C11 <threads.h>; unfortunately it is too early, so you'd need
> to write/borrow replacements for at least 3 of our 11 target systems
> * invent our own mini-abstraction for a carefully controlled subset of stuff
Google search on "c11 threads on Windows" found some emulation wrappers:
https://github.com/jtsiomb/c11threads and
https://github.com/tinycthread/tinycthread, for example. Would either of
those work for us?
Even if we use an existing emulation wrapper, I wouldn't mind having our
own pg_* abstration on top of it, to document which subset of the POSIX
or C11 functions we actually use.
--
Heikki Linnakangas
Neon (https://neon.tech)
Commits
-
Doc: Adjust libpq docs about thread safety.
- ce0b0fa3e792 17.0 landed
-
Remove --disable-thread-safety and related code.
- 68a4b58eca03 17.0 landed
-
Rename port/thread.c to port/user.c.
- 89333db963af 17.0 landed
-
Remove obsolete comment and code from fe-auth.c.
- 1aadc504bf47 17.0 landed