<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Hi Kristjan:</span></div><div><br></div>  <div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;"> <div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> <hr size="1">  </font></div><br>Message: 1<br>Date: Sun, 27 Jan 2013 16:26:13 +0000<br>From: Kristj?n Valur J?nsson <<a ymailto="mailto:kristjan@ccpgames.com" href="mailto:kristjan@ccpgames.com">kristjan@ccpgames.com</a>><br>To: "The Stackless Python Mailing List (<a ymailto="mailto:stackless@stackless.com" href="mailto:stackless@stackless.com">stackless@stackless.com</a>)"<br>    <<a ymailto="mailto:stackless@stackless.com" href="mailto:stackless@stackless.com">stackless@stackless.com</a>><br>Subject: [Stackless] the "atomic"
 flag<br>Message-ID:<br>    <<a ymailto="mailto:EFE3877620384242A686D52278B7CCD329E7399A@RKV-IT-EXCH103.ccp.ad.local" href="mailto:EFE3877620384242A686D52278B7CCD329E7399A@RKV-IT-EXCH103.ccp.ad.local">EFE3877620384242A686D52278B7CCD329E7399A@RKV-IT-EXCH103.ccp.ad.local</a>><br>Content-Type: text/plain; charset="iso-8859-1"<br><br>Interesting post. I haven't played with tasklet.atomic and read just enough about STM to be dangerous so here goes ....</div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"> <br>>I'd like to add the the new behavior of tasklet.atomic, to inhibit thread switching, is really only possible in our GIL based ?>cpython world.  But I actually view this as a benefit.  Given that the cpython implementation, the only current stackless >implemantaion, is GIL based, this makes ensuring local critical sections a
 breeze.<br><br>In keeping with the definition of atomic (and thinking about Armin Rigo's STM work), perhaps xxxx.atomic </div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57">is not so much  <span style="font-size: 12pt;">about inhibiting </span><span style="font-size: 12pt;">threading switch but rather guaranteeing:  an operation </span><span style="font-size: 12pt;">is all-or-nothing ; </span><span style="font-size: 12pt;">looks like a single operation from external threads of execution. </span></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><span style="font-size: 12pt;"><br></span></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><span style="font-size: 12pt;">(I say thread-of-execution
 rather than thread because it may be desirable to distinguish between OS threads,</span></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><span style="font-size: 12pt;">tasklets, and some other threading system. I haven't followed Armin's work lately but I was never sure how to make</span></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><span style="font-size: 12pt;">that system distinguish between a tasklet and a thread).</span></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><br>>In fact, so much so, that I would recommend this to the CPython crowd.  There is every so often the discussion here and >there whether this or that operation is 'atomic" or not.  Can list.appen() be considere atomic?  What
 about ordered >dictionary inserts?  Etc. etc. People discuss this back and forth and certain guarantees are made and not made.</div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><br></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57">I think list.append() should be atomic. As an interesting side-note, in the paper "Scalable Join Patterns," I believe</div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57">stuff like lock-free *bags*  (where order doesn't matter) are used to more efficiently implement concurrency.<br><br>>I'd argue that the stackless.atomic flag should be moved to be sys.atomic, and be per thread.  It should mean that there will >be no involountary gil based thread switches while it is in
 effect.<br>>It would solve a number of synchronization problems with thread based python.<br><br></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57">>Unfortunately, I see the counter arguments already:<br><br>>1)      It will not be truly atomic when there are blocking calls that truly do yield the GIL</div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><br></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57">It could still be truly atomic if the state of the "transaction" has not changed when control has been returned. However to handle this, I think one starts to head into STM land. </div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"
 class="yui_3_7_2_17_1359392628171_57"><br></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57">>2)      It is not portable to the versions of python that don't have a GIL.<br><br>I don't know enough about JPython and IronPython but "atomic" itself is a pretty general idea..</div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><br></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57">Cheers,</div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57">Andrew</div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;" class="yui_3_7_2_17_1359392628171_57"><br><br> </div> </div>  </div></body></html>