Re: libpq and multi-threading

Поиск
Список
Период
Сортировка
От Michael J. Baars
Тема Re: libpq and multi-threading
Дата
Msg-id CAMHx2Rs76akkVLTQ6Tr+fnVmZvwQfmM=iLJowW5ypePQDgbPDw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: libpq and multi-threading  (Laurenz Albe <laurenz.albe@cybertec.at>)
Ответы Re: libpq and multi-threading
Список pgsql-general
Hello Laurenz,

I don't think it is, but let me shed some more light on it.

After playing around a little with threads and memory, I now know that the PGresult is not read-only, it is read-once. The child can only read that portion of parent memory, that was written before the thread started. Read-only is not strong enough.

Let me correct my first mail. Making libpq use mmap is not good enough either. Shared memory allocated by the child can not be accessed by the parent. I remembered right after pushing the send button. Shared memory needed by the child therefore has to be allocated through the parent.

In conclusion. I have found no way to pass the PGresult around, other than by copying it to shared memory. Rather disappointing. One store too many if you ask me. But passing PGresults around freely between threads, because they are supposingly read-only, is not a finding that I was able to reproduce from here.

On Tue, 2 May 2023, 15:49 Laurenz Albe, <laurenz.albe@cybertec.at> wrote:
On Tue, 2023-05-02 at 11:38 +0200, Michael J. Baars wrote:
> I have a question about libpq and multi-threading.
>
> In the PostgreSQL documentation (https://www.postgresql.org/docs/15/libpq-threading.html)
> it says that results can be passed around freely between threads. However, when I try to read
> the result from the parent thread, the program crashes with a segmentation fault.

That's too little information.

Yours,
Laurenz Albe

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

Предыдущее
От: Laurenz Albe
Дата:
Сообщение: Re: libpq and multi-threading
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: libpq and multi-threading