Re: Using a latch between a background worker process and a thread

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Abbas Butt <abbas(dot)butt(at)enterprisedb(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Using a latch between a background worker process and a thread
Date: 2016-11-01 18:10:33
Message-ID: CA+TgmobB0Tu86G-USE5dHbwv9gvQ1ewzE+pX-H4Qa6RZsEXRSg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 1, 2016 at 12:35 PM, Abbas Butt <abbas(dot)butt(at)enterprisedb(dot)com> wrote:
> Hi,
> Consider this situation:
> 1. I have a background worker process.
> 2. The process creates a latch, initializes it using InitLatch & resets it.
> 3. It then creates a thread and passes the latch created in step 2 to it.
> To pass it, the process uses the last argument of pthread_create.
> 4. The thread blocks by calling WaitLatch.
> 5. The process after some time sets the latch using SetLatch.
>
> The thread does not notice that the latch has been set and keeps waiting.
>
> My question is:
> Are latches supposed to work between a process and a thread created by that
> process?

Nothing in the entire backend is guaranteed to work if you spawn
multiple threads within the same process.

Including this.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Francisco Olarte 2016-11-01 18:11:06 Re: Declarative partitioning - another take
Previous Message Robert Haas 2016-11-01 18:09:26 Re: Declarative partitioning - another take