<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 26, 2019, 09:50 Richard Whitehead <<a href="mailto:richard.whitehead@ieee.org">richard.whitehead@ieee.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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 dir="auto"><br></div><div dir="auto">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 dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> 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 dir="auto"><br></div><div dir="auto">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 dir="auto"><br></div><div dir="auto">-n</div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>