Hi Armin:

From: Armin Rigo <arigo@tunes.org>
To: Andrew Francis <andrewfr_ice@yahoo.com>
Cc: PyPy Developer Mailing List <pypy-dev@python.org>; "stackless@stackless.com" <stackless@stackless.com>
Sent: Sunday, April 1, 2012 5:23 AM
Subject: Re: The Work Plan Re: [pypy-dev] STM proposal funding

>I'm also thinking about writing a short paper collecting things I said
>and think on various blog posts.  A kind of "position paper".  What do
>others think of this idea?

I think this is a great idea.

>This is not discussed a lot right now.  But it is apparently
>relatively easy to adapt the epoll-based Twisted reactor to use the
>'transaction' module.  (Again, this module is present in the stm-gc
>branch; look for lib_pypy/transaction.py for the interface, and
>pypy/module/transaction/* for the Python implementation on top of STM
>as exposed by RPython.) In addition, each transaction can add more transactions that will be
>run after it.  So if you want to play with lib_pypy/stackless.py to
>add calls to 'transaction', feel free :-)  Maybe it will show that a
>slightly different API is required from the 'transaction' module; I
>don't really know so far.

Yes I can see transaction.add() being a wrapper/decorator for tasklet creation. However I think
that is the easy part. I'm trying to reason about the behaviour.

Starting with a simple Stackless programme:

1) All tasklets run on top of a single OS thread.
2) Tasklets do not yield until they are ready to commit, that is they do not call schedule() or block
on a channel .
3) Tasklets do not share state/ or variables are immutable ( because of #1 and #2, this isn't important)

This is a natural transaction

A more complicated but somewhat contrived scenario:

1) tasklets are still running over a single OS thread
2) tasklets yield
3) tasklets share state

def transactionA(account1, account2):
    account1.fromAccount -= 50
    if someRandomFunction():
       schedule()
    account2.toAccount += 50
  
def transactionB(account1, account2):
    t = arg.fromAccount * .1
   account1.fromAccount -= t
   if someRandomFunction():
      schedule()
   account2.toAccount += t

since the tasklets yield, this opens the door for race conditions. I need to look at how the underlying rstm module works to see how easy it would be detect conflicts amongst tasklets.

another scenario:

def transferTasklet(ch)
      ....
      while someFlag:
               toAcount, fromAccount, amount = ch.receive()
               # transaction start
                fromAccount.withdraw(amount)
                toAccount.deposit(amount)
               #transaction end

Question: without specific transaction_start() and transaction_commit() calls, how does rstm know what the start and finish of transactions are?

Cheers,
Andrew