Towards a formal account for software transactional memory Doriana - - PowerPoint PPT Presentation

towards a formal account for software transactional memory
SMART_READER_LITE
LIVE PREVIEW

Towards a formal account for software transactional memory Doriana - - PowerPoint PPT Presentation

Towards a formal account for software transactional memory Doriana Medi c Claudio Antares Mezzina Iain Phillips Nobuko Yoshida Reversible Computation July 9 - July 10, 2020, Oslo, Norway online event Introduction Reversible computing


slide-1
SLIDE 1

Towards a formal account for software transactional memory

Doriana Medi´ c Claudio Antares Mezzina Iain Phillips Nobuko Yoshida

Reversible Computation July 9 - July 10, 2020, Oslo, Norway

  • nline event
slide-2
SLIDE 2

Introduction

  • Reversible computing has been studied in several contexts ranging from

quantum computing, biochemical modelling, programming, and program debugging.

  • Of particular interest is its application to the study of programming

abstractions for reliable systems.

  • Distributed reversible actions can be seen as a building blocks for

different transactional models and recovery techniques.

1

slide-3
SLIDE 3
  • An example showing how notions of reversible and irreversible actions

in a process calculus can model a primitive form of transaction is given in [1].

  • On the shared memory side, we recall [2], where a CCS endowed with a

mechanism for software transactional memories (STMs) is presented and [3] which studies reversibility and a high-level abstraction of shared memory (tuple spaces).

[1] V. Danos and J. Krivine. Transactions in RCCS. [2] L. Acciai, M. Boreale and S. Dal-Zilio. A Concurrent Calculus with Atomic Transactions. [3] E. Giachino, I. Lanese, C. A. Mezzina and F. Tiezzi: Causal-consistent rollback in a tuple-based language.

2

slide-4
SLIDE 4

Software Transactional Memory

  • Software Transactional Memory is a way to address the problem of

concurrent programming, by relieving the programmer from the burden of dealing with locks.

  • Opposite to the lock-based approach, STM uses transactions, blocks of

code accessing shared data which are meant to be executed atomically.

  • It is necessary to specify the sequences of operations to be enclosed in

transactions, while the system is in charge of the interleaving between the concurrent transactions.

  • A transaction can either commit and update the system permanently
  • r abort and discard all the changes done by its execution.

3

slide-5
SLIDE 5

In this work:

  • our interest is in the interplay between reversible computing and the

STM approach to control the concurrent executions;

  • we present a formal framework for describing STMs in a simple shared

memory context;

  • a transaction can access a shared variable either in read or in write

mode;

  • we show how it is possible to model writer and reader preference in
  • ur framework;

4

slide-6
SLIDE 6

Example:

  • Consider the following C-like code where two functions/threads access

the same shared variables: int x = 0; int y = 5; int z = 0; void t1 () {z = y+x ; } void t2 () { x = z+1; }

  • The possible executions of the two functions are:

t1 ; t2 t2 ; t1 t1 | t2 z = 5 z = 6 z = 5 x = 6 x = 1 x = 1

  • Either the two functions are executed sequentially or are interleaved

(leading to an unwanted state).

5

slide-7
SLIDE 7

Syntax:

(Actions) α, β ::= wr(x) | rd(x) (Processes) A, B ::= 0 |

  • i

αi.Ai (Expressions) X, Y ::= B | α.X | X; Y | (X | Y ) | t : AΓ (Configuration) C ::= X M (Shared Memory) M ::= x, W , R M

6

slide-8
SLIDE 8

Syntax:

(Actions) α, β ::= wr(x) | rd(x) (Processes) A, B ::= 0 |

  • i

αi.Ai (Expressions) X, Y ::= B | α.X | X; Y | (X | Y ) | t : AΓ (Configuration) C ::= X M (Shared Memory) M ::= x, W , R M

6

slide-9
SLIDE 9

Syntax:

(Actions) α, β ::= wr(x) | rd(x) (Processes) A, B ::= 0 |

  • i

αi.Ai (Expressions) X, Y ::= B | α.X | X; Y | (X | Y ) | t : AΓ (Configuration) C ::= X M (Shared Memory) M ::= x, W , R M

6

slide-10
SLIDE 10

Syntax:

(Actions) α, β ::= wr(x) | rd(x) (Processes) A, B ::= 0 |

  • i

αi.Ai (Expressions) X, Y ::= B | α.X | X; Y | (X | Y ) | t : AΓ (Configuration) C ::= X M (Shared Memory) M ::= x, W , R M

6

slide-11
SLIDE 11

Syntax:

(Actions) α, β ::= wr(x) | rd(x) (Processes) A, B ::= 0 |

  • i

αi.Ai (Expressions) X, Y ::= B | α.X | X; Y | (X | Y ) | t : AΓ (Configuration) C ::= X M (Shared Memory) M ::= x, W , R M

6

slide-12
SLIDE 12

History context

A history context H is a process with a hole •, defined by the following grammar: H ::= • | α. • +A. Example: t : wr(x).rd(x1).rd(y).A + BΓ can be written as: t : H[rd(y).A]Γ where H = wr(x).rd(x1). • +B.

7

slide-13
SLIDE 13

History context

A history context H is a process with a hole •, defined by the following grammar: H ::= • | α. • +A. Example: t : wr(x).rd(x1).rd(y).A + BΓ can be written as: t : H[rd(y).A]Γ where H = wr(x).rd(x1). • +B.

  • To be able to identify the state of the internal computation of a transaction,

we mark it with symbol ∧. Example: in transition t : rd(x).rd(y).∧wr(z).wr(x′)Γ actions rd(x) and rd(y) are already executed.

7

slide-14
SLIDE 14

Write rule

(Wr) (W ⊆ {t} ∧ R ⊆ {t}) t : H[∧wr(x).A + B]Γ x, W , R M → t : H[wr(x).∧A + B]Γ x, W ∪ t, R M 8

slide-15
SLIDE 15

Write rule

(Wr) (W ⊆ {t} ∧ R ⊆ {t}) t : H[∧wr(x).A + B]Γ x, W , R M → t : H[wr(x).∧A + B]Γ x, W ∪ t, R M 8

slide-16
SLIDE 16

Write rule

(Wr) (W ⊆ {t} ∧ R ⊆ {t}) t : H[∧wr(x).A + B]Γ x, W , R M → t : H[wr(x).∧A + B]Γ x, W ∪ t, R M 8

slide-17
SLIDE 17

Write rule

(Wr) (W ⊆ {t} ∧ R ⊆ {t}) t : H[∧wr(x).A + B]Γ x, W , R M → t : H[wr(x).∧A + B]Γ x, W ∪ t, R M 8

slide-18
SLIDE 18

Write rule

(Wr) (W ⊆ {t} ∧ R ⊆ {t}) t : H[∧wr(x).A + B]Γ x, W , R M → t : H[wr(x).∧A + B]Γ x, W ∪ t, R M

Example:

t : ∧wr(x).rd(y)∅ x, ∅, ∅ y, ∅, ∅

8

slide-19
SLIDE 19

Write rule

(Wr) (W ⊆ {t} ∧ R ⊆ {t}) t : H[∧wr(x).A + B]Γ x, W , R M → t : H[wr(x).∧A + B]Γ x, W ∪ t, R M

Example:

t : ∧wr(x).rd(y)∅ x, ∅, ∅ y, ∅, ∅

8

slide-20
SLIDE 20

Write rule

(Wr) (W ⊆ {t} ∧ R ⊆ {t}) t : H[∧wr(x).A + B]Γ x, W , R M → t : H[wr(x).∧A + B]Γ x, W ∪ t, R M

Example:

t : ∧wr(x).rd(y)∅ x, ∅, ∅ y, ∅, ∅

t : wr(x).∧rd(y)∅

8

slide-21
SLIDE 21

Write rule

(Wr) (W ⊆ {t} ∧ R ⊆ {t}) t : H[∧wr(x).A + B]Γ x, W , R M → t : H[wr(x).∧A + B]Γ x, W ∪ t, R M

Example:

t : ∧wr(x).rd(y)∅ x, ∅, ∅ y, ∅, ∅

t : wr(x).∧rd(y)∅ x, {t}, ∅ y, ∅, ∅

8

slide-22
SLIDE 22

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M 9

slide-23
SLIDE 23

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M 9

slide-24
SLIDE 24

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M 9

slide-25
SLIDE 25

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M 9

slide-26
SLIDE 26

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M

Example:

t : wr(x).∧rd(y)∅ x, {t}, ∅ y, ∅, ∅

9

slide-27
SLIDE 27

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M

Example:

t : wr(x).∧rd(y)∅ x, {t}, ∅ y, ∅, ∅

9

slide-28
SLIDE 28

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M

Example:

t : wr(x).∧rd(y)∅ x, {t}, ∅ y, ∅, ∅

t : wr(x).rd(y)∧∅

9

slide-29
SLIDE 29

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M

Example:

t : wr(x).∧rd(y)∅ x, {t}, ∅ y, ∅, ∅

t : wr(x).rd(y)∧∅ x, {t}, ∅

9

slide-30
SLIDE 30

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M

Example:

t : wr(x).∧rd(y)∅ x, {t}, ∅ y, ∅, ∅

t : wr(x).rd(y)∧∅ x, {t}, ∅ y, ∅, {t}

9

slide-31
SLIDE 31

Read rule

(Rd) t : H[∧rd(x).A + B]Γ x, W , R M → t : H[rd(x).∧A + B]Γ∪(W \t) x, W , R ∪ t M

Example:

t : wr(x).∧rd(y)∅ x, {t}, ∅ y, ∅, ∅

t : wr(x).rd(y)∧∅ x, {t}, ∅ y, ∅, {t}

  • Transaction t can commit since all the actions inside of the transaction

are executed. When a transaction commits, it is discarded and its identifier is removed from the memory. Then we have:

0 x, ∅, ∅ y, ∅, ∅

9

slide-32
SLIDE 32

Rollback operator

  • a rollback operator is implemented following the approach given in [4].

Rollback operator The rollback operator on the transaction t : AΓ, written roll(t), is defined as: roll(t) = t : ∧A∅. Example: consider transaction t : rd(x).rd(y).∧wr(z).wr(x′)Γ then rollback of transaction t is: roll(t) = t : ∧rd(x).rd(y).wr(z).wr(x′)∅

[4] I. Lanese, C. A. Mezzina, A. Schmitt and J-B. Stefani. Controlling Reversibility in Higher-Order

10

slide-33
SLIDE 33

The example from introduction:

i n t x = 0; i n t y = 5; i n t z = 0; void t1 () {z = y+x ; } void t2 () { x = z+1; }

  • Abstracting away from the read and write values contained in variables

and representing accesses of two threads to the shared memory in our framework with transactions t1 and t2, we obtain a system:

t1 : ∧rd(y).rd(x).wr(z)]∅ | t2 : ∧rd(z).wr(x)]∅ x, ∅, ∅ y, ∅, ∅ z, ∅, ∅

11

slide-34
SLIDE 34

The example from introduction:

i n t x = 0; i n t y = 5; i n t z = 0; void t1 () {z = y+x ; } void t2 () { x = z+1; }

  • Abstracting away from the read and write values contained in variables

and representing accesses of two threads to the shared memory in our framework with transactions t1 and t2, we obtain a system:

t1 : ∧rd(y).rd(x).wr(z)]∅ | t2 : ∧rd(z).wr(x)]∅ x, ∅, ∅ y, ∅, ∅ z, ∅, ∅

  • After executing all read accesses of both transaction, we have:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

11

slide-35
SLIDE 35

Reader preference

  • With reader preference, we intend that no read access should be

suspended.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

.

12

slide-36
SLIDE 36

Reader preference

  • With reader preference, we intend that no read access should be

suspended.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • write access to variable z, done by transaction t1, is impossible since in

the memory z, ∅, {t2} we can see that some other transaction i.e. t2 already had a read access to the same variable. Therefore, transaction t1 will roll back. .

12

slide-37
SLIDE 37

Reader preference

  • With reader preference, we intend that no read access should be

suspended.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • write access to variable z, done by transaction t1, is impossible since in

the memory z, ∅, {t2} we can see that some other transaction i.e. t2 already had a read access to the same variable. Therefore, transaction t1 will roll back.

roll(t1) |

.

12

slide-38
SLIDE 38

Reader preference

  • With reader preference, we intend that no read access should be

suspended.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • write access to variable z, done by transaction t1, is impossible since in

the memory z, ∅, {t2} we can see that some other transaction i.e. t2 already had a read access to the same variable. Therefore, transaction t1 will roll back.

roll(t1) | t2 : rd(z).∧wr(x)]∅

.

12

slide-39
SLIDE 39

Reader preference

  • With reader preference, we intend that no read access should be

suspended.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • write access to variable z, done by transaction t1, is impossible since in

the memory z, ∅, {t2} we can see that some other transaction i.e. t2 already had a read access to the same variable. Therefore, transaction t1 will roll back.

roll(t1) | t2 : rd(z).∧wr(x)]∅ x, ∅, ∅

.

12

slide-40
SLIDE 40

Reader preference

  • With reader preference, we intend that no read access should be

suspended.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • write access to variable z, done by transaction t1, is impossible since in

the memory z, ∅, {t2} we can see that some other transaction i.e. t2 already had a read access to the same variable. Therefore, transaction t1 will roll back.

roll(t1) | t2 : rd(z).∧wr(x)]∅ x, ∅, ∅ y, ∅, ∅

.

12

slide-41
SLIDE 41

Reader preference

  • With reader preference, we intend that no read access should be

suspended.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • write access to variable z, done by transaction t1, is impossible since in

the memory z, ∅, {t2} we can see that some other transaction i.e. t2 already had a read access to the same variable. Therefore, transaction t1 will roll back.

roll(t1) | t2 : rd(z).∧wr(x)]∅ x, ∅, ∅ y, ∅, ∅ z, ∅, {t2}

.

12

slide-42
SLIDE 42

Reader preference

  • With reader preference, we intend that no read access should be

suspended.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • write access to variable z, done by transaction t1, is impossible since in

the memory z, ∅, {t2} we can see that some other transaction i.e. t2 already had a read access to the same variable. Therefore, transaction t1 will roll back.

roll(t1) | t2 : rd(z).∧wr(x)]∅ x, ∅, ∅ y, ∅, ∅ z, ∅, {t2}

where roll(t1) = t1 : ∧rd(y).rd(x).wr(z)]∅.

12

slide-43
SLIDE 43

Writer preference

  • Writer preference, allows the write access even if some read access

already took place. In this case, all the executing transactions with the read access to the same variable need to be rolled back.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

13

slide-44
SLIDE 44

Writer preference

  • Writer preference, allows the write access even if some read access

already took place. In this case, all the executing transactions with the read access to the same variable need to be rolled back.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • in this case, write access to variable z can be done and as a consequence

transition t2, having read access to variable z need to be rolled back.

13

slide-45
SLIDE 45

Writer preference

  • Writer preference, allows the write access even if some read access

already took place. In this case, all the executing transactions with the read access to the same variable need to be rolled back.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • in this case, write access to variable z can be done and as a consequence

transition t2, having read access to variable z need to be rolled back.

t1 : rd(y).rd(x).wr(z)∧∅ |

13

slide-46
SLIDE 46

Writer preference

  • Writer preference, allows the write access even if some read access

already took place. In this case, all the executing transactions with the read access to the same variable need to be rolled back.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • in this case, write access to variable z can be done and as a consequence

transition t2, having read access to variable z need to be rolled back.

t1 : rd(y).rd(x).wr(z)∧∅ | roll(t2)

13

slide-47
SLIDE 47

Writer preference

  • Writer preference, allows the write access even if some read access

already took place. In this case, all the executing transactions with the read access to the same variable need to be rolled back.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • in this case, write access to variable z can be done and as a consequence

transition t2, having read access to variable z need to be rolled back.

t1 : rd(y).rd(x).wr(z)∧∅ | roll(t2) x, ∅, {t1}

13

slide-48
SLIDE 48

Writer preference

  • Writer preference, allows the write access even if some read access

already took place. In this case, all the executing transactions with the read access to the same variable need to be rolled back.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • in this case, write access to variable z can be done and as a consequence

transition t2, having read access to variable z need to be rolled back.

t1 : rd(y).rd(x).wr(z)∧∅ | roll(t2) x, ∅, {t1} y, ∅, {t1}

13

slide-49
SLIDE 49

Writer preference

  • Writer preference, allows the write access even if some read access

already took place. In this case, all the executing transactions with the read access to the same variable need to be rolled back.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • in this case, write access to variable z can be done and as a consequence

transition t2, having read access to variable z need to be rolled back.

t1 : rd(y).rd(x).wr(z)∧∅ | roll(t2) x, ∅, {t1} y, ∅, {t1} z, {t1}, ∅

13

slide-50
SLIDE 50

Writer preference

  • Writer preference, allows the write access even if some read access

already took place. In this case, all the executing transactions with the read access to the same variable need to be rolled back.

  • Example:

t1 : rd(y).rd(x).∧wr(z)]∅ | t2 : rd(z).∧wr(x)]∅ x, ∅, {t1} y, ∅, {t1} z, ∅, {t2}

  • in this case, write access to variable z can be done and as a consequence

transition t2, having read access to variable z need to be rolled back.

t1 : rd(y).rd(x).wr(z)∧∅ | roll(t2) x, ∅, {t1} y, ∅, {t1} z, {t1}, ∅

where roll(t2) = t2 : ∧rd(z).wr(x)]∅

13

slide-51
SLIDE 51

Conclusion and Future Work

  • We have presented a framework to express the STM mechanism in a

simple shared memory context.

  • The framework is able to model two different policies for the execution
  • f the concurrent transactions: writer and reader preference.
  • Future work:
  • our aim is to start from a simple calculus and then to add (in a modular

way): nested transactions, data structures (e.g., C structures) and more complex scheduling policies.

  • having a modular framework, our goal is to prove that it satisfies the
  • pacity property, i.e that all the execution traces of our semantics, where

the transactional bodies are interleaved, are equivalent to executions in which transactional blocks are executed as a whole without being interleaved with other transactions.

14

slide-52
SLIDE 52

Thank you for attention

Questions?

15