<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: 'Calibri'; COLOR: #000000">
<DIV>Nathaniel,</DIV>
<DIV> </DIV>
<DIV>You’re quite right, I can’t work out the race condition myself now... Is it 
possible that an AutoResetEvent is just an Event with a two-line wait() 
overload???</DIV>
<DIV> </DIV>
<DIV>Richard</DIV>
<DIV> </DIV>
<DIV 
style='FONT-SIZE: small; TEXT-DECORATION: none; FONT-FAMILY: "Calibri"; FONT-WEIGHT: normal; COLOR: #000000; FONT-STYLE: normal; DISPLAY: inline'>
<DIV style="FONT: 10pt tahoma">
<DIV> </DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=njs@pobox.com>Nathaniel 
Smith</A> </DIV>
<DIV><B>Sent:</B> Tuesday, March 26, 2019 5:10 PM</DIV>
<DIV><B>To:</B> <A title=richard.whitehead@ieee.org>Richard Whitehead</A> </DIV>
<DIV><B>Cc:</B> <A title=python-ideas@python.org>Python-Ideas</A> </DIV>
<DIV><B>Subject:</B> Re: [Python-ideas] Simpler thread synchronization using 
"Sticky Condition"</DIV></DIV></DIV>
<DIV> </DIV></DIV>
<DIV 
style='FONT-SIZE: small; TEXT-DECORATION: none; FONT-FAMILY: "Calibri"; FONT-WEIGHT: normal; COLOR: #000000; FONT-STYLE: normal; DISPLAY: inline'>
<DIV>
<DIV>
<DIV class=gmail_quote>
<DIV class=gmail_attr dir=ltr>On Tue, Mar 26, 2019, 09:50 Richard Whitehead 
<<A>richard.whitehead@ieee.org</A>> wrote:<BR></DIV>
<BLOCKQUOTE class=gmail_quote 
style="PADDING-LEFT: 1ex; BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex">Nathaniel,<BR><BR>Thanks 
  very much for taking the time to comment.<BR><BR>Clearing the event after 
  waiting for it will introduce a race condition: if <BR>the sender has gone 
  around its loop again and set the semaphore after we <BR>have woken but before 
  we've cleared it.</BLOCKQUOTE></DIV></DIV>
<DIV> </DIV>
<DIV>Sounds fine to me. Why is that a problem? Can you write down an example of 
how two threads could be interleaved to produce incorrect results?</DIV>
<DIV> </DIV>
<DIV>
<DIV class=gmail_quote>
<BLOCKQUOTE class=gmail_quote 
style="PADDING-LEFT: 1ex; BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex">As 
  you said, this stuff is tricky! <BR>The only safe way is to make the 
  wait-and-clear atomic, which can be done <BR>with a lock; and this comes 
  essentially back to what I'm proposing.<BR><BR>I realise this is not a 
  fundamental new primitive - if it was, I wouldn't be <BR>able to build it in 
  pure Python - but I've found it extremely useful in our <BR>generic threading 
  and processing library.<BR><BR>You're right about what you say regarding 
  queues; I didn't want to go into <BR>the full details of the multi-threading 
  and multi-processing situation at <BR>hand, but I will say that we have a 
  pipeline of tasks that can run as either <BR>threads or processes, and we want 
  to make it easy to construct this <BR>pipeline, "wiring" it as necessary; 
  combining command queues with data <BR>queues just gets a real 
mess.<BR></BLOCKQUOTE></DIV></DIV>
<DIV> </DIV>
<DIV>But you're effectively implementing a multi-producer single-consumer Queue 
anyway, so without any details it's hard to guess why using a Queue would be 
messier. I know you don't want to get into too many details, but if the whole 
motivation for your proposal is based on some details then it's usually a good 
idea to explain them :-).</DIV>
<DIV> </DIV>
<DIV>-n</DIV>
<DIV>
<DIV class=gmail_quote>
<BLOCKQUOTE class=gmail_quote 
style="PADDING-LEFT: 1ex; BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex"></BLOCKQUOTE></DIV></DIV></DIV></DIV></DIV></DIV></BODY></HTML>