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

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Aug 6 08:50:49 EDT 2016



On 08/06/2016 01:09 PM, Jun Wu wrote:
> Excerpts from Augie Fackler's message of 2016-08-05 14:22:09 -0400:
>> 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
>
> I just got confirmation by arigato on #pypy that this also works in Pypy.
> Same to "set.pop()". I will use the later so address the "send SIGTERM
> to waited processes" issue and mention Pypy in commit message.

If we have anything smart relying on set.pop() being atomical, we should 
add an inline comment to point it out.

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list