Search Postgresql Archives

Re: libpq and multi-threading

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx> 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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux