Re: Cleaning up threading code

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема Re: Cleaning up threading code
Дата
Msg-id 7c8fc64b-eeb3-4fac-9c83-ccb0bf246d4a@iki.fi
обсуждение исходный текст
Ответ на Re: Cleaning up threading code  (Peter Eisentraut <peter@eisentraut.org>)
Ответы Re: Cleaning up threading code  (Thomas Munro <thomas.munro@gmail.com>)
Re: Cleaning up threading code  (Thomas Munro <thomas.munro@gmail.com>)
Список pgsql-hackers
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)

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: CI and test improvements
Следующее
От: Daniel Gustafsson
Дата:
Сообщение: Re: On /*----- comments