Re: parallel mode and parallel contexts - Mailing list pgsql-hackers

From Robert Haas
Subject Re: parallel mode and parallel contexts
Date
Msg-id CA+TgmoZpBFoXNmHRt13ktKJR1RXmABbKusd6rz9Z=EqBDLUrVA@mail.gmail.com
Whole thread Raw
In response to Re: parallel mode and parallel contexts  (Amit Kapila <amit.kapila16@gmail.com>)
List pgsql-hackers
On Fri, Mar 6, 2015 at 7:01 AM, Amit Kapila <amit.kapila16@gmail.com> wrote:
> Today, while testing parallel_seqscan patch, I encountered one
> intermittent issue (it hangs in below function) and I have question
> related to below function.
>
> +void
> +WaitForParallelWorkersToFinish(ParallelContext *pcxt)
> +{
> ..
> + for (;;)
> + {
> ..
> + CHECK_FOR_INTERRUPTS();
> + for (i = 0; i < pcxt->nworkers; ++i)
> + {
> + if (pcxt->worker[i].error_mqh != NULL)
> + {
> + anyone_alive = true;
> + break;
> + }
> + }
> +
> + if (!anyone_alive)
> + break;
> +
> + WaitLatch(&MyProc->procLatch, WL_LATCH_SET, -1);
> + ResetLatch(&MyProc->procLatch);
> + }
>
> Isn't there a race condition in this function such that after it finds
> that there is some alive worker and before it does WaitLatch(), the
> worker completes its work and exits, now in such a case who is
> going to wake the backend waiting on procLatch?

It doesn't matter whether some other backend sets the process latch
before we reach WaitLatch() or after we begin waiting.  Either way,
it's fine.

It would be bad if the process could exit without setting the latch at
all, though.  I hope that's not the case.

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



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: parallel mode and parallel contexts
Next
From: Stephen Frost
Date:
Subject: Re: MD5 authentication needs help