On Fri, Mar 6, 2015 at 7:01 AM, Amit Kapila <amit.kapil...@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 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers