Haskell: how does TVAR work?

How does TVAR work? From what I can see, it tries to run all transactions as soon as it receives them, but transaction completion invalidates other currently running transactions and must then be restarted Is this how TVAR works?

If this is the case, if 1ms long transactions occur every 100ms, does it mean that transactions requiring 200ms will never be completed?

Solution

As long as two transactions access different TVs, they can commit at the same time without invalidating each other

To clearly illustrate when a transaction fails, let's consider the following scenarios:

>Suppose T:: TVAR int is initialized to 0 and read through readtvar t at the beginning of transaction A. > At the same time, in another thread, start transaction B, where writetvar t 1.0 is executed Suppose B submits before a The STM system will check whether there are any inconsistencies and conclude that B is safe to submit at this time, so writetvar T 1 takes effect now. > However, this will invalidate transaction a because the old 0 value is read at the beginning of a (if a is allowed to commit, we will violate atomicity.)

The original paper on Haskell's STM system [1] (see section 6.5) answers your question:

[1] Tim Harris, Simon Marlow, Simon Peyton Jones and Maurice Herlihy ACM 2005 parallel programming principles and Practice Conference (ppopp'05)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>