[PATCH 6 of 7 V3] worker: test and set problem[0] atomically

Jun Wu quark at fb.com
Sat Aug 6 05:40:09 EDT 2016


Excerpts from Yuya Nishihara's message of 2016-08-06 12:09:36 +0900:
> On Fri, 5 Aug 2016 14:22:09 -0400, Augie Fackler wrote:
> > On Thu, Aug 04, 2016 at 07:29:07PM +0100, Jun Wu wrote:
> > > # HG changeset patch
> > > # User Jun Wu <quark at fb.com>
> > > # Date 1470334096 -3600
> > > #      Thu Aug 04 19:08:16 2016 +0100
> > > # Node ID d08d72f5d8bf302dd1231be410d0b23dc082eb66
> > > # Parent  d179a66b0b15988687ba9d69c5b76e4464a457eb
> > > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r d08d72f5d8bf
> > > worker: test and set problem[0] atomically
> > >
> > > Previously problem[0] is not tested and set atomically:
> > >
> > >     if st and not problem[0]:
> > >         # at this time, another SIGCHILD happens, killworkers may run twice
> > >         problem[0] = st
> > >         killworkers()
> > >
> > > This patch addresses the issue by using itertools.count(). Its CPython
> > > implementation will make it "atomic" at the Python code level, which is
> > > enough for our use-case (signal handler).
> > 
> > This is very clever, but:
> > 
> > 1) pypy is already a thing
> > 2) It's very clever
> > 
> > Could we just use a conventional lock of some sort instead?
> 
> or could we make killworkers() safe for multiple calls?
>
>   pids = set(...)
>   while pids:
>       try:
>           p = pids.pop()
>       except KeyError:
>           break
>       kill(p)

This relies on pop() being "atomic". I guess it still has issues with pypy.

> Anyway, the current killworkers() doesn't care for pid reuse. It could send
> SIGTERM to already-waited pids.


More information about the Mercurial-devel mailing list