<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Software Transactional Memory with Interactions?</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Marino Miculan</string-name>
          <email>marino.miculan@uniud.it</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Marco Peressotti</string-name>
          <email>peressotti@imada.sdu.dk</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Southern Denmark</institution>
          ,
          <country country="DK">Denmark</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>University of Udine</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Software Transactional memory (STM) is an emerging abstraction for concurrent programming alternative to lock-based synchronizations. Most STM models admit only isolated transactions, which are not adequate in multithreaded programming where transactions need to interact via shared data before committing. To overcome this limitation, in this paper we present Atomic Transactional Memory (ATM), a programming abstraction supporting safe, data-driven interactions between composable memory transactions. This is achieved by relaxing isolation between transactions, still ensuring atomicity. This model allows for loosely-coupled interactions since transaction merging is driven only by accesses to shared data, with no need to specify participants beforehand.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Modern multicore architectures have emphasized the importance of abstractions
supporting correct and scalable multi-threaded programming. In this model,
threads can collaborate by interacting on shared data structures, such as tables,
message queues, buffers, etc., whose access must be regulated to avoid
inconsistencies. Traditional lock-based mechanisms (like semaphores and monitors)
are notoriously difficult and error-prone, as they easily lead to deadlocks, race
conditions and priority inversions; moreover, they are not composable and hinder
parallelism, thus reducing efficiency and scalability. Transactional memory (TM)
has emerged as a promising abstraction to replace locks [
        <xref ref-type="bibr" rid="ref19 ref5">5, 19</xref>
        ]. The basic idea
is to mark blocks of code as atomic; then, execution of each block will appear
either as if it was executed sequentially and instantaneously at some unique
point in time, or, if aborted, as if it did not execute at all. This is obtained by
means of optimistic executions: these blocks are allowed to run concurrently, and
eventually if an interference is detected a block is automatically restarted after
that its effects are rolled back. Thus, each transaction can be viewed in isolation
as a single-threaded computation, significantly reducing the programmer’s burden.
Moreover, transactions are composable and ensure absence of deadlocks and
priority inversions, automatic roll-back on exceptions, and increased concurrency.
      </p>
      <p>However, in multi-threaded programming transactions may need to interact
and exchange data before committing. In this situation, transaction isolation is a
severe shortcoming. A simple example is a request-response interaction between
two transactions via a shared buffer. We could try to synchronize the threads
accessing the buffer b by means of two semaphores c1, c2 as follows:
// Party1 (Master)
atomically {
&lt;put request in b&gt;
up(c1);
&lt;some other code; may abort&gt;
down(c2); // wait for answer
&lt;get answer from b; may abort&gt;
}
// Party2 (Worker)
atomically {
down(c1); // wait for data
&lt;get request from b&gt;
&lt;compute answer; may abort&gt;
&lt;put answer in b&gt;
up(c2);
}
Unfortunately, this solution does not work: any admissible execution requires
an interleaved scheduling between the two transactions, thus violating isolation;
hence, the transactions deadlock as none of them can progress. It is important
to notice that this deadlock arises because interaction occurs between threads
of different transactions; in fact, the solution above is perfectly fine for threads
outside transactions or within the same transaction.</p>
      <p>To overcome this limitation, in this paper we propose a programming model for
safe, data-driven interactions between memory transactions. The key observation
is that atomicity and isolation are two disjoint computational aspects:
– an atomic non-isolated block is executed “all-or-nothing”, but its execution
can overlap others’ and uncontrolled access to shared data is allowed;
– a non-atomic isolated block is executed “as if it were the only one” (i.e., in
mutual exclusion with others), but no rollback on errors is provided.
Thus, a “normal” block of code is neither atomic nor isolated; a mutex block
(like Java synchronized methods) is isolated but not atomic; and a usual STM
transaction is a block which is both atomic and isolated.</p>
      <p>
        Our claim is that atomic non-isolated blocks can be fruitfully used for
implementing safe composable interacting memory transactions. In this model, which
we call Atomic Transactional Memory (ATM), a transaction is composed by
several threads, called participants, which can cooperate on shared data. A
transaction commits when all its participants commit, and aborts if any thread aborts.
Threads participating to different transactions can access to shared data, but
when this happens the transactions are transparently merged into a single one.
For instance, the two transactions of the synchronization example above would
automatically merge becoming the same transaction, so that the two threads can
synchronize and proceed. Thus, this model relaxes the isolation requirement still
guaranteeing atomicity and consistency; moreover, it allows for loosely-coupled
interactions since transaction merging is driven only by run-time accesses to shared
data, without any explicit coordination among the participants beforehand.
Related work. Many authors have proposed mechanisms to allow transactions
to interact. Perhaps the work closest to ours are transaction communicators
(TC) [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. A transaction communicator is a (Java) object which can be accessed
simultaneously by many transactions. To guarantee consistency, dependencies
between transactions are maintained at runtime: a transaction can commit only
when every transactions it depends on also commit. When dependencies form a
cycle, the involved transactions must either all commit or abort together. This
differs from ATM approach, where cooperating transactions are dynamically
merged and hence the dependency graph is always acyclic; thus, ATM is opaque
whereas TC is not. Other differences between TC and ATM are that our model
has a formal semantics and that it can be implemented without changing neither
the compiler nor the runtime (albeit it may be not very efficient).
      </p>
      <p>
        Other authors have proposed events- and message passing -based mechanisms;
we mention transactional events (TE) [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], which are specialized to the composition
of send/receive operations to simplify synchronization in communication protocols,
and TIC [
        <xref ref-type="bibr" rid="ref20">20</xref>
        ], where a transaction can be split into an isolated and a non-isolated
transactions; this may violate local invariants and hence TIC does not satisfy
opacity. Finally, communicating memory transactions (CMT) [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] is a model
combining memory transactions with the actor model yielding transactors; hence
CMT can be seen as the message-oriented counterpart of TC. CMT is opaque
and has an efficient implementation; however it is best suited to distributed
scenarios, whereas TC and ATM are aimed to multi-threaded programming on
shared memory—in fact, transactors can be easily implemented in ATM by means
of queues on shared memory. Another difference is that channel topology among
transactors is established a priori, i.e. when the threads are created, while in ATM
threads are created at runtime and interactions between transactions are driven
by access to shared data only, whose references can be acquired at runtime.
Synopsis. In Section 2 we present Atomic Transactional Memory in the context
of Concurrent Haskell. In Section 3 we provide a formal operational semantics.
which is used in Section 4 to prove that ATM satisfies the opacity correctness
criterion. Concluding remarks and directions for future work are in Section 5.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Haskell interface for Isolated and atomic transactions</title>
      <p>In this section we give a brief overview of the interface for atomic transactions
for Haskell. In fact, ATM can be implemented in any programming language,
provided we have some means to forbid irreversible effects inside transactions;
we have chosen Haskell because its typing system allows us to implement this
restriction quite easily. Namely, we define two monads ATM and ITM (see Figure 1),
representing the computational aspects of atomic multi-threaded atomic,
nonisolated transactions and atomic single-threaded isolated transactions, respectively.
Transactional memory locations are values of type ATVar and can be manipulated
by isolated transactional actions only.</p>
      <p>Using the construct atomic, programs in the ATM monad are executed
“all-ornothing” but without isolation; hence these transactions can merge at runtime.
-- Types for transactional actions
-----------------------------------------data ITM a -- isolated atomic transactional action, return a value of type a
data ATM a -- non-isolated atomic transaction, return a value of type a
-- Sequencing, do notation. Here t is a placeholder for ITM or ATM
---------(&gt;&gt;=) :: t a -&gt; (a -&gt; t b) -&gt; t b
return :: a -&gt; t a
-- Running isolated and atomic actions
-------------------------------------atomic :: ATM a -&gt; IO a -- deliver the IO action for an atomic one
isolated :: ITM a -&gt; ATM a -- deliver the atomic action for an isolated one
retry :: ITM a -- retry the current transaction
orElse :: ITM a -&gt; ITM a -&gt; ITM a -- fall back on the second action when
-- the first action issues a retry
-- Exceptions
--------------------------------------------------------------throw :: Exception e =&gt; e -&gt; t a
catch :: Exception e =&gt; t a -&gt; (e -&gt; t a) -&gt; t a
-- Threading
---------------------------------------------------------------fork :: ATM () -&gt; ATM ThreadId
-- Transactional shared memory
---------------------------------------------data ATVar a -- sharable memory location holding values of type a
newATVar :: a -&gt; ITM (ATVar a)
readATVar :: ATVar a -&gt; ITM a
writeATVar :: ATVar a -&gt; a -&gt; ITM ()</p>
      <p>
        When needed, actions inside transactions can be executed in isolation by using the
construct isolated. Both ATM and ITM transactions are composable; we exploit
Haskell type system to prevent irreversible effects inside these monads. ATM is
a conservative extension of STM [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]; in fact, STM’s atomically is precisely the
composition of atomic and isolated (Figure 2). This allows programmers to
decide the granularity of interactions; e.g., the snippet below combines read and
write actions to define an isolated atomic update of a transactional location.
modifyATVar :: ATVar a -&gt; (a -&gt; a) -&gt; ITM ()
modifyATVar var f = do
x &lt;- readATVar var
writeATVar var (f x)
Invariants on transactional locations can be easily checked by composing reads
with checks that issue a retry if the invariant is not met, as in the snippet below.
assertATVar :: ATVar a -&gt; (a -&gt; Bool) -&gt; ITM ()
assertATVar var p = do
x &lt;- readATVar var
if (p x) then return () else retry
By sharing ATVars, non-isolated actions can share their view of transactional
memory and affect each other. Consistency is guaranteed by merging transactions
upon interaction thus the merged transaction may commit only if all participants
agree on the final state of shared ATVars.
      </p>
      <sec id="sec-2-1">
        <title>Example 2.1. Semaphores can be implemented in</title>
        <p>ATM as ATVars holding a counter and operation
up and down as atomic and isolated actions. The
first increments the counter held by the semaphore
and the second decrements it when the counter is
positive or retries the transaction otherwise thus
blocking the thread.
tu
type Semaphore = ATVar Int
up :: Semaphore -&gt; ITM ()
up s = modifyATVar s (1+)
down :: Semaphore -&gt; ITM ()
down s = do
assertATVar s (&gt; 0)
modifyATVar s (-1+)
Example 2.2. A Petri net is readily implemented in ATM by representing each
transition by a thread and each place by a semaphore. Putting and taking a token
from a place correspond to increasing (up) or decreasing (down) its semaphore—
the latter blocks if no tokens are available. Each thread repeatedly simulates
the firing of the transition it represents, by taking tokens from its input places
and putting tokens in its output places. These semaphore operations must be
performed atomically but not in isolation: isolation would prevent transitions
sharing a place to fire concurrently. Using ATM, all this is achieved in few lines:
type Place = Semaphore
transition :: [Place] -&gt; [Place] -&gt; IO ThreadId
transition inputs outputs = forkIO (forever fire)
where
fire = atomic $ do
mapM_ (isolated . down) inputs
mapM_ (isolated . up) outputs
Observe that, since firing is atomic but not isolated, this is an implementation
of true concurrent Petri nets, which is usually more difficult to achieve than
interleaving semantics. Here is a simple Petri net and its implementation:
main = do
p1 p2 p1 &lt;- atomically (newPlace 1)</p>
        <p>p2 &lt;- atomically (newPlace 0)
t1 t2 p3 &lt;- atomically (newPlace 0)
p4 &lt;- atomically (newPlace 0)
transition [p1] [p3, p4]
p3 p4 transition [p1, p2] [p4]
When t1 or t2 race to take the token in p1, if t2 takes it first the transaction will
eventually retry since there is no token in p2.
tu</p>
      </sec>
      <sec id="sec-2-2">
        <title>More examples can be found in [15].</title>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Formal semantics of ATM</title>
      <p>
        In this section we provide the formal semantics of ATM. Following [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], we fix
an Haskell-like language extended with the ATM primitives of Figure 1 and
characterise the behaviour of ATM by means of an abstract machine.
      </p>
      <p>The language syntax is given by the following grammar:
Values V ::= r j \x -&gt; M j return M j M &gt;&gt;= N j throw M j catch M N
j putChar c j getChar j fork M j atomic M j isolated M j retry
j M ‘orElse‘ N j newATVar M j readATVar r j writeATVar r M</p>
      <p>Terms M ::= x j V j M N
where the meta-variables x and r range over a given countable set of variables Var
and of location names Loc, respectively. We assume Haskell typing conventions
and denote the set of all well-typed terms by Term.</p>
      <p>Terms are evaluated by an abstract state machine whose states are pairs hP ; i
formed by: (a) a thread family (or process) P = Tt1 k k Ttn where ti are unique
thread identifiers; (b) a memory = h ; ; i, where : Loc * Term is the heap
and : Loc * Term TrName is the working memory ; TrName is a set of names
used to identify active transactions; is a forest of threads identifiers keeping track
of how threads have been forked. Threads are the smaller unit of execution the
machine scheduler operates on; they evaluate ATM terms and do not have any private
transactional memory. A thread Tt has two forms: ([M ])t for threads evaluating a
term M outside a transaction and ([M ; N ])t;k for threads evaluating M inside
transaction k with continuation N (the term to evaluate after that k has committed).</p>
      <p>
        As for traditional closed (ACID) transactions (e.g., [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]), operations inside
a transaction are evaluated against the distributed working memory and
effects are propagated to the heap only on commits. When a thread inside a
transaction k accesses a location outside the location is claimed by transaction
k and remains claimed until k commits, aborts or restarts. Threads in k can
interact only with locations claimed by k, but active transactions can be merged
to share their claimed locations. We denote the set of all possible states as State,
and reference to each projected component of by a subscript, i.e. for the
heap and for the working memory. When describing updates to the memory
, we adopt the convention that 0 has to be intended equals to except if
stated otherwise, i.e. by statements like 0 = [r 7! M ]. Finally, ? denotes
the empty heap and working memory.
      </p>
      <p>Semantics The machine dynamics is defined by the two transition relations
induced by the rules in Figures 3 to 6; auxiliary definitions are in Figure 7.</p>
      <p>The first relation M ! N is defined on terms only, and models pure
computations (Figure 3). In particular, rule Eval allows a term M that is not a value
to be evaluated by means of an auxiliary (partial) function V[M ] yielding the
value V ; the other rules define the semantics of the monadic bind and exception
handling in a standard way. It is interesting to notice the symmetry between</p>
      <p>Eval
return M &gt;&gt;= N ! N M
r 2 fretry; return N g CatchVal
r ‘catch‘ M ! r</p>
      <p>BindVal
e 2 fretry; throw N g BindEx</p>
      <p>e &gt;&gt;= M ! e
throw M ‘catch‘ N ! N M</p>
      <p>CatchEx
h([atomic M &gt;&gt;= N ])t; i newhk!i h([M ; N ])t;k; i
0 = commit(k; )</p>
      <p>0 = cleanup(k; )
0 = leak(k; )
h([return M ; N ])t;k; i cohk!i h([return M &gt;&gt;= N ])t; 0i
0 = cleanup(k; ) 0 = remove(r; ) r = root(t;
New</p>
      <p>Commit
h([throw M ; N ])t;k; i abhk;t;M!i h([throw M &gt;&gt;= N ])t; 0i
hP ; i
bind and catch and how retry is treated as an exception by rule BindEx and
as a result value by rule CatchVal.</p>
      <p>Relation ! is used to define the labelled transition relation hP ; i ! hP 0; 0i
over states. This relation is non deterministic, to model the fact that the scheduler
can choose among various threads to execute next; therefore, several rules can
apply to a given state according to different evaluation contexts:</p>
      <sec id="sec-3-1">
        <title>Expression:</title>
        <p>E ::=[ ] j E &gt;&gt;= M
Transaction: Tt;k ::=([E; M ])t;k k P
Plain process: Pt ::=([E])t k P
Any process: At ::=Pt j Tt;k</p>
        <sec id="sec-3-1-1">
          <title>Labels describe the kind of transition, and are defined as follows:</title>
          <p>::=</p>
          <p>j newhki j cohki j abhk; t; M i j abhk; t; M i j ?c j !c
where k 2 TrName; M 2 Term as usual.</p>
          <p>Transitions labelled by represent internal steps of transactions, i.e., which
do not need any coordination: reduction of pure terms, memory operations and</p>
          <p>k Ttn ) , ft1; : : : tng
transaction( ) , k for</p>
          <p>2 fnewhki; cohki; abhk; t; M i; abhk; t; M ig
( [k 7! j])(r) ,
( (r)</p>
          <p>if (r) = (M; l); l 6= k
(M; j) if (r) = (M; k)
8&gt;transactions(P1) [ transactions(P2) if P = P1 k P2
transactions(P ) , &lt;fkg if P = ([M ; N ])t;k
&gt;:; otherwise
P [k 7! j] ,
8&gt;P1[k 7! j] k P2[k 7! j] if P = P1 k P2
&lt;([M ; N ])t;j if P = ([M ; N ])t;k
&gt;:P otherwise
[r 7! M ](s) , if r = s then M else (s)
[r 7! (M; k)](s) , if r = s then (M; k) else (s)
cleanup(k; )(r) , if
commit(k; )(r) , if
(r) = (M; k) then ? else
(r) = (M; k) then M else
(r)
(r)
leak(k; )(r) , M if
(r) = M or
(r) = ? and
(r) = (M; k)
thread creation (see rules in Figure 5). Reading a location falls into two cases:
rule Read1 models the reading of an unclaimed location and its effect is to record
the claim in , while rule Read2 models the reading of a claimed location and
its effect is to merge the transactions of the current thread with that claiming the
location. Writes behave similarly. Rules Or1 and Or2 describe the semantics
of alternative sub-transactions: if the first one retry-es the second is executed
discarding any effect of the first. Rule ForkT spawns a new thread for the
current transaction; a term fork M can appear inside atomic, thus allowing
multi-threaded atomic transactions, but its use inside isolated is prevented by
the type system and by the shape of rule Isolated as well.</p>
          <p>The remaining labels describe state transitions concerning the life-cycle
of transactions: creation, commit, abort, and restart (see rules in Figure 6).
These operations require a coordination among threads; for instance, an abort
from a thread has to be propagated to every thread participating to the same
transaction. This is captured in the semantics by labelling the transition with
the operation and the name of the transaction involved; this information is used
to force synchronisation of all participants of that transaction. To illustrate this
mechanism, we describe the commit of a transaction k, namely hP ; i cohk!i
hP 0; 0i. First, by means of rule MCastGroup we split P into two subprocesses,
one of which contains all threads participating in k (those not in k cannot do a
transition whose label contains k). Secondly, using recursively rule MCastCo
we single out every thread in k. Finally, we apply rule Commit provided that
every thread is ready to commit, i.e., it is of the form ([return M ; N ])t;k.</p>
          <p>
            Aborting a transaction works similarly, but it based on vetoes instead of an
unanimous vote. Aborts are triggered by unhandled exceptions raised by some
thread, but threads react to this situation in different ways:
– threads forked within the transaction, in the same tree of the thread raising
the exception: these threads are killed (and the root thread aborted) because
their creation must be discarded, as for any transactional side-effect;
– threads from different trees which joined the transaction after it was created,
due to a merging: these threads just retry their transaction, since aborting
would require them to handle exceptions raised by “foreign” threads.
Like Haskell STM [
            <xref ref-type="bibr" rid="ref4">4</xref>
            ], aborts leak some effects namely any transactional variable
created in the aborted transaction that also occurs in the aborting exception.
          </p>
          <p>Note that there are no derivation rules for retry: its meaning is to inform the
scheduler that we have reached a state where the execution is stuck; hence the
machine has to re-execute the transaction from the beginning (or backtracking
from a suitable check-point), possibly following a different execution order.
4</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Opacity</title>
      <p>
        In this section we validate the formal semantics of ATM by proving it satisfies the
opacity correctness criterion for transactional memory [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. This criterion is an
extension of the classical serialisability property for databases with the additional
requirement that even non-committed transactions must access consistent states.
Intuitively, this property ensures that (a) effects of any committed transaction
appear performed at a single, indivisible point during the transaction lifetime;
(b) updates of any aborted transaction cannot be seen by other transactions;
(c) transactions always access consistent states of the system.
      </p>
      <p>
        In order to formally capture these intuitive requirements let us recall some
notions from [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. A history is a sequence of read, write, commit, and abort
operations ordered according to the time at which they were issued (simultaneous
events are arbitrarily ordered) and such that no operation can be issued by a
transaction that has already performed a commit or an abort. A transaction k
is said to be in a history H if the latter contains at least one operation issued
by k. Histories that differ only for the relative position of operations in different
transactions are considered equivalent. Any history H defines a happens-before
partial order H over transactions, where k H k0 iff the transaction k becomes
committed or aborted in H before k0 issues its first operation. If H is total then
H is called sequential. For a history H, let complete(H) be the set of histories
obtained by adding either a commit or an abort for every live transaction in H.
      </p>
      <p>We can now recall Guerraoui-Kapałka’s definition3 of opacity [3, Def. 1].
Definition 4.1 (Opacity). A history H is said to be opaque if there exists
a sequential history S equivalent to some history in complete(H) such that S
preserves the happens-before order of H.
3 The original definition requires the history H to be “legal”, but this notion is relevant
only in presence of non-transactional operations which ATM prevents by design.</p>
      <p>
        As shown in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], opacity corresponds to the absence of mutual dependencies
between live transactions, where a dependency is created whenever a transaction
reads an information written by another or depends from its outcome.
Definition 4.2 (Opacity graph [3, Sec. 5.4]). For a history H let be a
total order on the set T of all transactions in H. An opacity graph OP G(H; )
is a bi-coloured directed graph on T such that a vertex is red if the corresponding
transaction is either running or aborted, it is black otherwise, and for all vertices
k; k0 2 T , there is a edge k ! k0 if any of the following holds:
      </p>
      <sec id="sec-4-1">
        <title>1. k0 happens-before k (k0 H k);</title>
        <p>2. k reads something written by k0;
3. k0 reads some location written by k and k0 k;
4. k0 is neither running nor aborted and there are a location r and a transaction
k00 such that k0 k00, k0 writes to r, and k00 reads r from k.</p>
        <p>The edge is red if the second case applies, otherwise it is black. The graph is said
to be well-formed if all edges from red nodes in OP G(H; ) are also red.</p>
        <p>Let H be a history and let k be a transaction appearing in it. A read operation
by k is said to be local (to k) whenever the previous operation by k on the same
location was a write. A write operation by k is said to be local (to k) whenever
the next operation by k on the same location is a write. We denote by nonlocal (H)
the longest sub-history of H without any local operations. A history H is said
locally-consistent if every local read is preceded by a write operation that writes
the read value; it is said consistent if, additionally, whenever some k reads v from
r in nonlocal (H) then some k0 writes v to r in nonlocal (H).</p>
        <p>Theorem 4.1 ([3, Thm. 2]). A history H is opaque if and only if (a) H is
consistent and (b) there exists a total order on the set of transactions in H
such that OP G(nonlocal (H); ) is well-formed and acyclic.</p>
        <p>
          In [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ] transactions may encapsulate several threads but cannot be merged.
Therefore, in order to study opacity of ATM we extend the set of operations
considered in loc. cit. with explicit merges. Let k; k0 be two running transactions
in the given history; when they merge, they share their threads, locations, and
effects. From this perspective, k is commit-pending and depends from k0 and
hence in the opacity graph, k is a red node connected to k0 by a red edge. Hence,
merges can be equivalently expressed at the history level by sequences like:
(1) new x; (2) k0 writes on x; (3) k reads from x; (4) k prepares to commit.
These are the only dependencies found in histories generated by ATM.
Theorem 4.2. For H a history describing an execution of a ATM program and
a total order , OP G(nonlocal (H); ) is a forest of red edges where only roots
may be black.
        </p>
        <p>Proof. By inspection of the rules it is easy to see that (a) transactions may access
only locations they claimed; (b) claimed locations are released only on commits,
aborts and retries; (c) transactions have to merge with any transaction holding
a location they need. Therefore, at any given time there is at most one running
transaction issuing operations on a given location, hence reads and writes do not
create edges. Thus edges are created only during the execution of merges and, by
inspecting the above implementation, it easy to see that (d) any transaction can
issue at most one merge; (e) a transaction issuing a merge is a red node; (f ) the
edge created by a merge is red. Therefore, transactions form a forest made of red
edges where any non-root node is red.
tu</p>
        <p>Since a forest formed by red edges whose sources are always red is always
acyclic and well-formed, we can conclude our correctness result:
Corollary 4.1 (Opacity). ATM meets the opacity criterion.
5</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Conclusions and future work</title>
      <p>In this paper we have presented ATM, a programming model supporting
interactions between composable memory transactions. This model separates isolated
transactions from non-isolated ones, still guaranteeing atomicity; the latter can
interact by accessing to shared variables. Consistency is ensured by transparently
merging interacting transactions at runtime. We have given a formal semantics
for ATM, and proved that this model satisfies the important opacity criterion.</p>
      <p>
        As future work, it would be interesting to add some heuristics to better
handle retry events. Currently, a retry restarts all threads participating to the
transaction; a more efficient implementation would keep track of the working
set of each thread, and at a retry we need to restart only the threads whose
working sets have non-empty intersection with that being restarted. Another
optimization is to implement transactions and ATVars directly in the runtime,
akin the implementation of STM in the Glasgow Haskell Compiler [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>We have presented ATM within Haskell (especially to leverage its type system),
but this model is general and can be applied to other languages. A possible future
work is to port this model to an imperative object oriented language, such as Java
or C++; however, like other TM implementations, we expect that this extension
will require some changes in the compiler and/or the runtime.</p>
      <p>
        This work builds on the calculus with shared memory and atomic transactions
described in [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ]. In op. cit. this model is shown to be expressive enough to
represent T CCSm [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], a variant of the Calculus of Communicating Systems with
transactional synchronization. The relation is strict since there are no sensible
ways to represent in T CCSm features like unbounded memory allocation, aliasing
and higher-order computations. The lack of such correspondence calls for an
extension of T CCSm with name mobility and restriction, i.e. a variant of the
-calculus with transactional communication. Close to this line of investigation is
the study of interacting transactions in the setting of [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ]. Being based on CCS,
communication in T CCSm is synchronous; however, nowadays asynchronous
models play an important rôle (see actors, event-driven programming, etc.), so
it may be interesting to generalize the model to consider also this case, e.g. by
defining a calculus for event-driven models or an actor-based calculus with atomic
transactions. Such a calculus can be quite useful also for modelling speculative
reasoning for cooperating systems [
        <xref ref-type="bibr" rid="ref10 ref11 ref12 ref13">10–13</xref>
        ] or study distributed interacting
transactions in serverless-computing [
        <xref ref-type="bibr" rid="ref18 ref2 ref6">2, 6, 18</xref>
        ]. A local version of actor-based atomic
transactions can be implemented in ATM using lock-free data structures (e.g.,
message queues) in shared transactional memory.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>K.</given-names>
            <surname>Donnelly</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.</given-names>
            <surname>Fluet</surname>
          </string-name>
          .
          <article-title>Transactional events</article-title>
          .
          <source>J. Funct. Program.</source>
          ,
          <volume>18</volume>
          (
          <issue>5-6</issue>
          ):
          <fpage>649</fpage>
          -
          <lpage>706</lpage>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>M.</given-names>
            <surname>Gabbrielli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Giallorenzo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>I.</given-names>
            <surname>Lanese</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Montesi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Peressotti</surname>
          </string-name>
          , and
          <string-name>
            <given-names>S. P.</given-names>
            <surname>Zingaro</surname>
          </string-name>
          .
          <article-title>No more, no less - A formal model for serverless computing</article-title>
          .
          <source>In COORDINATION</source>
          , volume
          <volume>11533</volume>
          of Lecture Notes in Computer Science, pages
          <fpage>148</fpage>
          -
          <lpage>157</lpage>
          . Springer,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>R.</given-names>
            <surname>Guerraoui</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.</given-names>
            <surname>Kapalka</surname>
          </string-name>
          .
          <article-title>On the correctness of transactional memory</article-title>
          .
          <source>In Proceedings of the 13th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming</source>
          ,
          <source>PPoPP '08</source>
          , pages
          <fpage>175</fpage>
          -
          <lpage>184</lpage>
          , New York, NY, USA,
          <year>2008</year>
          . ACM.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>T.</given-names>
            <surname>Harris</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Marlow</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S. L. Peyton</given-names>
            <surname>Jones</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Herlihy</surname>
          </string-name>
          .
          <article-title>Composable memory transactions</article-title>
          .
          <source>In Proc. PPOPP</source>
          , pages
          <fpage>48</fpage>
          -
          <lpage>60</lpage>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>M.</given-names>
            <surname>Herlihy</surname>
          </string-name>
          and
          <string-name>
            <given-names>J. E. B.</given-names>
            <surname>Moss</surname>
          </string-name>
          .
          <article-title>Transactional memory: Architectural support for lock-free data structures</article-title>
          . In A. J. Smith, editor,
          <source>Proceedings of the 20th Annual International Symposium on Computer Architecture</source>
          . San Diego, CA, May
          <year>1993</year>
          , pages
          <fpage>289</fpage>
          -
          <lpage>300</lpage>
          . ACM,
          <year>1993</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>A.</given-names>
            <surname>Jangda</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Pinckney</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Brun</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Guha</surname>
          </string-name>
          .
          <article-title>Formal foundations of serverless computing</article-title>
          .
          <source>Proc. ACM Program. Lang.</source>
          ,
          <volume>3</volume>
          (OOPSLA):
          <volume>149</volume>
          :
          <fpage>1</fpage>
          -
          <lpage>149</lpage>
          :
          <fpage>26</fpage>
          ,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>V.</given-names>
            <surname>Koutavas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Spaccasassi</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Hennessy</surname>
          </string-name>
          .
          <article-title>Bisimulations for communicating transactions - (extended abstract)</article-title>
          . In A. Muscholl, editor,
          <source>Foundations of Software Science and Computation Structures - 17th International Conference, FOSSACS</source>
          <year>2014</year>
          ,
          <article-title>Held as Part of the European Joint Conferences on Theory and Practice of Software</article-title>
          ,
          <source>ETAPS</source>
          <year>2014</year>
          , Grenoble, France, April 5-
          <issue>13</issue>
          ,
          <year>2014</year>
          , Proceedings, volume
          <volume>8412</volume>
          of Lecture Notes in Computer Science, pages
          <fpage>320</fpage>
          -
          <lpage>334</lpage>
          . Springer,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>M.</given-names>
            <surname>Lesani</surname>
          </string-name>
          and
          <string-name>
            <given-names>J.</given-names>
            <surname>Palsberg</surname>
          </string-name>
          .
          <article-title>Communicating memory transactions</article-title>
          . In C. Cascaval and P. Yew, editors,
          <source>Proceedings of the 16th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, PPOPP</source>
          <year>2011</year>
          , San Antonio, TX, USA, February
          <volume>12</volume>
          -
          <issue>16</issue>
          ,
          <year>2011</year>
          , pages
          <fpage>157</fpage>
          -
          <lpage>168</lpage>
          . ACM,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>V.</given-names>
            <surname>Luchangco</surname>
          </string-name>
          and
          <string-name>
            <given-names>V. J.</given-names>
            <surname>Marathe</surname>
          </string-name>
          .
          <article-title>Transaction communicators: Enabling cooperation among concurrent transactions</article-title>
          .
          <source>In Proceedings of the 16th ACM Symposium on Principles and Practice of Parallel Programming</source>
          ,
          <source>PPoPP '11</source>
          , pages
          <fpage>169</fpage>
          -
          <lpage>178</lpage>
          , New York, NY, USA,
          <year>2011</year>
          . ACM.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>J.</given-names>
            <surname>Ma</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Broda</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Goebel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Hosobe</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Russo</surname>
          </string-name>
          , and
          <string-name>
            <given-names>K.</given-names>
            <surname>Satoh</surname>
          </string-name>
          .
          <article-title>Speculative abductive reasoning for hierarchical agent systems</article-title>
          . In J. Dix,
          <string-name>
            <given-names>J.</given-names>
            <surname>Leite</surname>
          </string-name>
          , G. Governatori, and W. Jamroga, editors,
          <source>Computational Logic in MultiAgent Systems</source>
          , volume
          <volume>6245</volume>
          of Lecture Notes in Computer Science, pages
          <fpage>49</fpage>
          -
          <lpage>64</lpage>
          . Springer Berlin Heidelberg,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>A.</given-names>
            <surname>Mansutti</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Miculan</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Peressotti</surname>
          </string-name>
          <article-title>. Multi-agent systems design and prototyping with bigraphical reactive systems</article-title>
          . In K. Magoutis and P. Pietzuch, editors,
          <source>Proc. DAIS</source>
          , volume
          <volume>8460</volume>
          of Lecture Notes in Computer Science, pages
          <fpage>201</fpage>
          -
          <lpage>208</lpage>
          . Springer,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>A.</given-names>
            <surname>Mansutti</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Miculan</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Peressotti</surname>
          </string-name>
          .
          <article-title>Distributed execution of bigraphical reactive systems</article-title>
          .
          <source>ECEASST</source>
          ,
          <volume>71</volume>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>A.</given-names>
            <surname>Mansutti</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Miculan</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Peressotti</surname>
          </string-name>
          .
          <article-title>Towards distributed bigraphical reactive systems</article-title>
          . In R. Echahed,
          <string-name>
            <given-names>A.</given-names>
            <surname>Habel</surname>
          </string-name>
          , and M. Mosbah, editors,
          <source>Proc. GCM'14, page 45</source>
          ,
          <year>2014</year>
          . Workshop version.
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>D.</given-names>
            <surname>Medic</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C. A.</given-names>
            <surname>Mezzina</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Phillips</surname>
          </string-name>
          , and
          <string-name>
            <given-names>N.</given-names>
            <surname>Yoshida</surname>
          </string-name>
          .
          <article-title>Towards a formal account for software transactional memory</article-title>
          .
          <source>In RC</source>
          , volume
          <volume>12227</volume>
          of Lecture Notes in Computer Science, pages
          <fpage>255</fpage>
          -
          <lpage>263</lpage>
          . Springer,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>M.</given-names>
            <surname>Miculan</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.</given-names>
            <surname>Peressotti</surname>
          </string-name>
          .
          <article-title>Software transactional memory with interactions</article-title>
          .
          <source>CoRR</source>
          , abs/
          <year>2007</year>
          .10809,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <given-names>M.</given-names>
            <surname>Miculan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Peressotti</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Toneguzzo</surname>
          </string-name>
          .
          <article-title>Open transactions on shared memory</article-title>
          .
          <source>In COORDINATION</source>
          , volume
          <volume>9037</volume>
          of Lecture Notes in Computer Science, pages
          <fpage>213</fpage>
          -
          <lpage>229</lpage>
          . Springer,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Ni</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Menon</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Adl-Tabatabai</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. L.</given-names>
            <surname>Hosking</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. L.</given-names>
            <surname>Hudson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. E. B.</given-names>
            <surname>Moss</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Saha</surname>
          </string-name>
          , and
          <string-name>
            <given-names>T.</given-names>
            <surname>Shpeisman</surname>
          </string-name>
          .
          <article-title>Open nesting in software transactional memory</article-title>
          . In K. A. Yelick and
          <string-name>
            <surname>J. M.</surname>
          </string-name>
          Mellor-Crummey, editors,
          <source>Proceedings of the 12th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, PPOPP</source>
          <year>2007</year>
          , San Jose, California, USA, March
          <volume>14</volume>
          -17,
          <year>2007</year>
          , pages
          <fpage>68</fpage>
          -
          <lpage>78</lpage>
          . ACM,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <given-names>M.</given-names>
            <surname>Obetz</surname>
          </string-name>
          ,
          <string-name>
            <surname>A. Das</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          <string-name>
            <surname>Castiglia</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          <string-name>
            <surname>Patterson</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Milanova</surname>
          </string-name>
          .
          <article-title>Formalizing event-driven behavior of serverless applications</article-title>
          .
          <source>In ESOCC</source>
          , volume
          <volume>12054</volume>
          of Lecture Notes in Computer Science, pages
          <fpage>19</fpage>
          -
          <lpage>29</lpage>
          . Springer,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [19]
          <string-name>
            <given-names>N.</given-names>
            <surname>Shavit</surname>
          </string-name>
          and
          <string-name>
            <given-names>D.</given-names>
            <surname>Touitou</surname>
          </string-name>
          .
          <article-title>Software transactional memory</article-title>
          .
          <source>Distributed Computing</source>
          ,
          <volume>10</volume>
          (
          <issue>2</issue>
          ):
          <fpage>99</fpage>
          -
          <lpage>116</lpage>
          ,
          <year>1997</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          [20]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Smaragdakis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Kay</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Behrends</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Young</surname>
          </string-name>
          .
          <article-title>Transactions with isolation and cooperation</article-title>
          . In R. P. Gabriel,
          <string-name>
            <given-names>D. F.</given-names>
            <surname>Bacon</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C. V.</given-names>
            <surname>Lopes</surname>
          </string-name>
          , and
          <string-name>
            <given-names>G. L. S.</given-names>
            <surname>Jr</surname>
          </string-name>
          ., editors,
          <source>Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications</source>
          ,
          <source>OOPSLA 2007, October 21-25</source>
          ,
          <year>2007</year>
          , Montreal, Quebec, Canada, pages
          <fpage>191</fpage>
          -
          <lpage>210</lpage>
          . ACM,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>