Re: libpq and multi-threading

From: "Michael J(dot) Baars" <mjbaars1977(dot)pgsql(dot)hackers(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Subject: Re: libpq and multi-threading
Date: 2023-05-02 15:43:06
Message-ID: CAMHx2Rs76akkVLTQ6Tr+fnVmZvwQfmM=iLJowW5ypePQDgbPDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)albe(at)cybertec(dot)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
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2023-05-02 15:57:14 Re: libpq and multi-threading
Previous Message Laurenz Albe 2023-05-02 13:49:00 Re: libpq and multi-threading