<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Hi Armin:<br></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;"> <font face="Arial" size="2"> <hr size="1">  <b><span style="font-weight: bold;">From:</span></b> Armin Rigo &lt;arigo@tunes.org&gt;<br> <b><span style="font-weight: bold;">To:</span></b> PyPy Developer Mailing List &lt;pypy-dev@python.org&gt; <br> <b><span style="font-weight: bold;">Sent:</span></b> Wednesday, January 4, 2012 6:30 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> [pypy-dev] STM<br> </font> <br>&gt;While this is obvious in the case of the CPython interpreter, I'd<br>&gt;argue that it is a useful point of view in general.&nbsp; The paper<br>&gt;mentioned above says that the current
 approach to multithreading is<br>&gt;completely non-deterministic, <br><br>....<br><br>A silly question? What is the paper you are discussing? <br><br>&gt; The solution that we really need for<br>&gt;CPython requires a different point of view: a generally-STM program,<br>&gt;in which we carefully add here and there a "yield", i.e. a point at<br>&gt;which it's ok to end the current transaction and start the next one.<br><br>...<br><br>&gt;(Interestingly, this run() function is similar to stackless.run().<br>&gt;The exact relationships between stackless and this model are yet to<br>&gt;investigate, but it seems that one point of view on what I'm proposing<br>&gt;might be essentially "use stackless, remove some determinism from the<br>&gt;already-unclear tasklet switching order, and add STM under the hood".)<br><br>Perhaps this is off-topic, in&nbsp; non-trivial stackless programme using cooperative scheduling, <br>unless you explicitly impose a logical
 ordering, it is difficult to predict when a particular tasklet <br>will&nbsp; run. The round-robin doesn't mean much. This is because in non-trivial stackless programmes,&nbsp; <br>like most non-trivial multi-threaded programmes, coroutines are responding to external events that <br>arrive with some degree of randomness. To cop a line from the creator of Erlang,"the world is concurrent."<br>This is also why I didn't quite get the extreme measures to inject non-determinism in the Newsqueak<br>interpreter so the programmer can't second guess the scheduler.<br><br>I will be the first to admit that I have a half-baked knowledge of STM. And I have just started looking<br>at the C++ Transactional language specification. And I have a sketchy knowledge of CPython <br>interpreter. So I have a lot to learn and probably many misconceptions. <br><br>I can sort of see the Stackless angle: in the simplest case a tasklet that does not share data with other
 <br>tasklets  (in this case, it can yield without problems), communications only via channels, or uses set_atomic() looks like a coarse-grained transaction of sorts..... <br><br>Based on the little I know about stuff like transactional synchronisation order, in a Stackless <br>programme, I can see a beginTransaction like statement acting like a natural yield/schedule() point. Marking transactions boundaries is useful. If another transaction is occuring, the tasklet/thread suspends. Otherwise the tasklet/thread starts its transaction until it finishes. <br><br>One may be able to model this with stackless.py .....<br><br>If I understand what you are proposing, the problem I see with yielding in the coarse-grained tasklet-as-transaction, is that you probably need more machinery to ensure ACID properties, since you are now getting thread interweaving and potential race conditions.<br><br>&gt;and add STM under the hood".<br><br>When I did my join pattern
 prototype, I read the paper "Scalable Join Patterns." A conversation with the authors lead to reading stuff on Concurrent/Parallel ML and "Transactional Events." The common strategy in all those projects was to use STM related technologies under the hood to support a higher level concurrency construct while reducing the performance hit.<br><br>Cheers,<br>Andrew<br><br><br> </div> </div>  </div></body></html>