Szumo: A Compositional Contract Model for Safe Multi- Threaded - - PowerPoint PPT Presentation

szumo a compositional contract model for safe multi
SMART_READER_LITE
LIVE PREVIEW

Szumo: A Compositional Contract Model for Safe Multi- Threaded - - PowerPoint PPT Presentation

Szumo: A Compositional Contract Model for Safe Multi- Threaded Applications LASER 2005 Laura K. Dillon Software Engineering & Network Systems Laboratory Michigan State University ldillon@cse.msu.edu Laser 2005 - Summer School on 1


slide-1
SLIDE 1

Laser 2005 - Summer School on Software Engineering 1

Szumo: A Compositional Contract Model for Safe Multi- Threaded Applications

LASER 2005

Laura K. Dillon Software Engineering & Network Systems Laboratory Michigan State University

ldillon@cse.msu.edu

slide-2
SLIDE 2

Laser 2005 - Summer School on Software Engineering 2

Credits

♦ Creators: Reimer Behrends, R. E. Kurt Stirewalt ♦ Financial Support:

– US Department of the Navy, ONR grant N00014-01- 1-0744 – National Science Foundation grants EIA-0000433, CCR-9901017, CCR-9984727, CDA-9617310, and CCR-9896190 – US Defense Advance Research Projects Agency, DASADA program

slide-3
SLIDE 3

Laser 2005 - Summer School on Software Engineering 3

Synchronization Units Model

♦ Problem: Synchronization concerns in multi- threaded object-oriented programs complicate designs

– Difficult to modularize – A source of brittleness

♦ Goal: Facilitate extension, maintenance and evolution through better modularization of synchronization concerns ♦ Idea: Associate synchronization contracts with modules and automatically infer necessary synchronization logic from the contracts

slide-4
SLIDE 4

Laser 2005 - Summer School on Software Engineering 4

Overview of lecture series

♦ Background ♦ Introduction to Szumo ♦ Case study ♦ Semantic and implementation details ♦ Related concurrency models ♦ Ongoing and future work

slide-5
SLIDE 5

Laser 2005 - Summer School on Software Engineering 5

Overview of lecture series

♦ Background

– Contracts – Multi-threaded OO programs – Concurrency problems

♦ Introduction to Szumo ♦ Case study ♦ Semantic and implementation details ♦ Related concurrency models ♦ Ongoing and future work

slide-6
SLIDE 6

Laser 2005 - Summer School on Software Engineering 6

Contracts

Formal Agreement between a supplier and its clients ♦ Parties have rights and responsibilities ♦ Improved documentation, verification, separation of concerns ♦ Can enable optimizations

sqrt( x : REAL ) : REAL is require x >= 0 do … end

Zen and the art of sw reliability: guarantee more by checking less!

slide-7
SLIDE 7

Laser 2005 - Summer School on Software Engineering 7

Level 1: Syntactic Level 2: Behavioral Level 3: Synchronization Level 4: QOS

Degree of Contract Awareness

Higher degrees:

– Support contracting over non-functional properties – Enable dynamic client-supplier negotiation of services

Contract awareness

♦ Different degrees of strength [Beugnard et al.’99]:

slide-8
SLIDE 8

Laser 2005 - Summer School on Software Engineering 8

Overview of lecture series

♦ Background

– Contracts – Multi-threaded OO programs – Concurrency problems

♦ Introduction to Szumo ♦ Case study ♦ Semantic and implementation details ♦ Related concurrency models ♦ Ongoing and future work

slide-9
SLIDE 9

Laser 2005 - Summer School on Software Engineering 9

Multi-threaded OO Program

♦ Multiple threads manipulate passive objects in shared memory ♦ Major concurrency concern: Threads within critical regions require exclusive access to shared objects ♦ Designer must identify and protect these critical regions without introducing concurrency errors (e.g., deadlock, starvation).

slide-10
SLIDE 10

Laser 2005 - Summer School on Software Engineering 10

Example: Dining Philosophers

Three philosophers sit around a circular table set with three forks and a large bowl of spaghetti. Each philosopher alternates between thinking and eating ad infinitum. To eat, a philosopher picks up the fork to her left and then the fork to her right. After eating, she returns the forks to their places and then proceeds to think.

slide-11
SLIDE 11

Laser 2005 - Summer School on Software Engineering 11

Example: Dining Philosophers in Java

p0: Phil p1: Phil f0: Fork f1: Fork f2: Fork left right p0: Phil right left right left Class Phil extends Thread { private Fork left; private Fork right; . . . public void run( ) { while (true) { think(); left.get(this); right.get(this); eat(); // using left & right right.put(this); left.put(this); } } . . . }

slide-12
SLIDE 12

Laser 2005 - Summer School on Software Engineering 12

Example: Dining Philosophers in Java

p2: Phil p1: Phil f0: Fork f1: Fork f2: Fork left right right left right left Class Fork { private boolean taken = false; . . . synchronized void get(Phil p) { while (taken) wait (); taken = true; …println( p.toString() + “ picked up ” + toString()); } synchronized void put(Phil p) { …println( p.toString() + “ put down ” + toString()); taken = false; notifyAll(); } . . . } p0: Phil

slide-13
SLIDE 13

Laser 2005 - Summer School on Software Engineering 13

Overview of lecture series

♦ Background

– Contracts – Multi-threaded OO programs – Concurrency problems

♦ Introduction to Szumo ♦ Case study ♦ Semantic and implementation details ♦ Related concurrency models ♦ Ongoing and future work

slide-14
SLIDE 14

Laser 2005 - Summer School on Software Engineering 14

Problem: Interleaving of concurrency logic with “functional” logic

Class Fork { private boolean taken = false; . . . synchronized void put(Phil p) { …println( p.toString() + “ put down ” + this.toString(); taken = false; notifyAll(); } synchronized void get(Phil p) { while (taken) wait (); taken = true; …println( p.toString() + “ picked up ” + this.toString(); } Class Phil extends Thread { private Fork left; private Fork right; . . . public void run( ) { while (true) { think(); left.get(this); right.get(this); eat(); right.put(this); left.put(this); } } . . . }

slide-15
SLIDE 15

Laser 2005 - Summer School on Software Engineering 15

Problem: Undocumented synchronization rights and responsibilities

♦ Philosopher’s right / Fork’s responsibility:

– A philosopher has exclusive access to a fork after calling “get” until the next call to “put”

♦ Philosopher’s responsibility / Fork’s right:

– A philosopher alternates in first calling “get” and then “put” – A philosopher uses a fork only between a call to “get” and the next call to “put”

Unstated correctness criteria produce brittle designs

slide-16
SLIDE 16

Laser 2005 - Summer School on Software Engineering 16

Behavior contracts can express limited synchronization rights and responsibilities

Class Fork { private Philosopher holder; . . . synchronized void put(Phil p) require (holder == p) { …println( p.toString() + “ put down ” + this.toString(); holder = null; notifyAll(); } synchronized void get(Phil p) require (holder != p) { while (holder != null) wait (); holder = p; …println( p.toString() + “ picked up ” + this.toString(); }

♦ Here, only clients’ responsibilities / suppliers’ rights ♦ Cannot express the mutual exclusion right / responsibility

slide-17
SLIDE 17

Laser 2005 - Summer School on Software Engineering 17

Problem: Failure to “protect” critical regions

♦ E.g., omit call(s) to “…get(…)” or omit assignment to “taken” in “get” method ♦ Data race: uncoordinated access to shared data (in this case, f2) ♦ Data races are difficult to detect and isolate

p0: Phil p2: Phil p1: Phil f0: Fork f2: Fork left right right left right left f1: Fork

slide-18
SLIDE 18

Laser 2005 - Summer School on Software Engineering 18

Problem: Potential for starvation

p2: Phil p1: Phil f0: Fork f1: Fork f2: Fork left right right left right left p0: Phil p0: Phil p2: Phil p1: Phil f0: Fork f1: Fork f2: Fork left right right left right left

slide-19
SLIDE 19

Laser 2005 - Summer School on Software Engineering 19

Problem: Potential for deadlock

♦ Root cause: incrementally acquiring multiple shared

  • bjects for some critical

region ♦ Well-known solution: Impose an acquisition

  • rder on the objects

♦ Requires: Global agreement on the acquisition order

p0: Phil p2: Phil p1: Phil f0: Fork f1: Fork f2: Fork left right right left right left

slide-20
SLIDE 20

Laser 2005 - Summer School on Software Engineering 20

Detour: Enforcing an acquisition order

Class Phil extends Thread { private Fork left; private Fork right; . . . private void reserveTwo( ) { if (left < right) { left.reserve(); right.reserve(); } else { right.reserve(); left.reserve(); } } private void unreserveTwo() { left.unreserve(); right.unreserve(); } . . . public void run( ) { while (true) { think(); reserveTwo(); left.get(this); right.get(this); eat(); right.put(this); left.put(this); unreserveTwo(); } } . . . }

slide-21
SLIDE 21

Laser 2005 - Summer School on Software Engineering 21

Detour: Enforcing an acquisition order

Class Fork { . . . synchronized void reserve() { while (taken) wait (); taken = true; } synchronized void unreserve() { taken = false; notifyAll(); } synchronized void get(Phil p) { …println( p.toString() + “ picked up ” + toString() ); } synchronized void put(Phil p) { …println( p.toString() + “ put down ” + toString() ); } . . . }

slide-22
SLIDE 22

Laser 2005 - Summer School on Software Engineering 22

The “ordered-acquisition solution” may not apply: ♦ If suppliers are not known a priori, but can change during execution ♦ If a client has indirect suppliers (transitive access dependences)

Problem: Potential for deadlock

c0: C s1: S s0: S c1: C

c0’s direct supplier, s0, should encapsulate its indirect supplier, s1; similarly for c1 Thus, c0 acquires s0 and then s1; but c1 acquires s1 and then s0 !

slide-23
SLIDE 23

Laser 2005 - Summer School on Software Engineering 23

Summary of problems

♦ Interleaving of concurrency logic with “functional” logic ♦ Undocumented rights and responsibilities ♦ Failure to “protect” critical regions ♦ Potential for deadlock and starvation

slide-24
SLIDE 24

Laser 2005 - Summer School on Software Engineering 24

Overview of lecture series

♦ Background ♦ Introduction to Szumo ♦ Case study ♦ Semantic and implementation details ♦ Related concurrency models ♦ Ongoing and future work

slide-25
SLIDE 25

Laser 2005 - Summer School on Software Engineering 25

Overview of lecture series

♦ Background ♦ Introduction to Szumo

– Key concepts – Revisit concurrency problems

♦ Case study ♦ Semantic and implementation details ♦ Related concurrency models ♦ Ongoing and future work

slide-26
SLIDE 26

Laser 2005 - Summer School on Software Engineering 26

Goal for Szumo

Facilitate building multi-threaded OO programs that: ♦ Are easily extended and maintained ♦ Are free from data races ♦ Avoid deadlock and starvation

slide-27
SLIDE 27

Laser 2005 - Summer School on Software Engineering 27

Szumo in a nutshell

♦ Executing program is a (dynamically evolving) set of synchronization units ♦ Synch. units are organized into an accessing graph

– Partitioned into disjoint sub-graphs, called realms – One realm for each thread of control – A thread has exclusive access to the units in its realm

♦ Synchronization contracts

– Define the synchronization states of a unit – Specify the suppliers accessed in each synchronization state – Govern the migration of units among realms

♦ Safety and liveness

– Data races prevented by efficient run-time checks – Realm construction automates deadlock/starvation avoidance

slide-28
SLIDE 28

Laser 2005 - Summer School on Software Engineering 28

Key concepts

♦ Synchronization unit ♦ Synchronization contract ♦ Concurrency constraint ♦ Realm ♦ Contract negotiation

Note: From here onward, examples are given in Szumo Eiffel

slide-29
SLIDE 29

Laser 2005 - Summer School on Software Engineering 29

Concept: Synchronization unit

♦ A cohesive collection of objects

– Determine the granularity of sharing – Related by creation

♦ Root object serves as the unit’s representative

– Created from a synchronization class – Syntax: decorate a class definition with the keyword “synchronization”

synchronization class PHIL . . . end synchronization class FORK . . . end

slide-30
SLIDE 30

Laser 2005 - Summer School on Software Engineering 30

Concept: Synchronization Contract

♦ Declared in the concurrency clause of a client ♦ Consists of one or more concurrency constraints

synchronization class PHIL . . . feature . . . . . . concurrency . . . end -- PHIL f0: Fork f1: Fork right left p0: Phil

slide-31
SLIDE 31

Laser 2005 - Summer School on Software Engineering 31

Concept: Concurrency constraint

Expressed in terms of: ♦ unit variables

– Provide references to the suppliers that the unit might access

♦ condition variables

– Define the unit’s synchronization states – A philosopher has two synchronization states: eating and !eating

synchronization class PHIL . . . feature left, right: FORK eating: BOOLEAN . . . concurrency . . . end -- PHIL

slide-32
SLIDE 32

Laser 2005 - Summer School on Software Engineering 32

Concept: Concurrency constraint

Simplest form: P => U

a unit variable a predicate over condition variables

Meaning: When P is true, the client needs exclusive access to the supplier, if any, referenced by U

synchronization class PHIL . . . eating: BOOLEAN left, right: FORK concurrency eating => left and right end -- PHIL

abbreviates: eating => left eating => right

slide-33
SLIDE 33

Laser 2005 - Summer School on Software Engineering 33

Terminology

♦ The constraint is triggered in c if P is true ♦ The constraint is cancelled in c if P is false ♦ If the constraint is triggered in c then c entails the unit that U references ♦ Entails(c) denotes the set of units that c entails, also called c’s entailment

synchronization class CLIENT . . . . . . concurrency P => U . . . end -- CLIENT

If c denotes an instance of a class CLIENT with constraint P => U:

slide-34
SLIDE 34

Laser 2005 - Summer School on Software Engineering 34

synchronization class FORK . . . feature . . . get(p: PHIL) is do print_string(p.to_string + “ picked up ” + to_string + “%N”) end -- get put(p: PHIL) is do print_string(p.to_string + “ put down ” + to_string + “%N”) end -- put end -- FORK

Example

♦ FORK, a supplier (only), has no synchronization contract

slide-35
SLIDE 35

Laser 2005 - Summer School on Software Engineering 35

synchronization class PHIL . . . feature left, right: FORK eating: BOOLEAN . . . start is do from until false loop think eating := true left.get(Current) right.get(Current) eat right.put(Current) left.put(Current) eating := false end end -- start concurrency eating => left and right end -- PHIL constraint is cancelled constraint is triggered

Example

♦ PHIL, a client, needs exclusive access to both left and right while eating

slide-36
SLIDE 36

Laser 2005 - Summer School on Software Engineering 36

f0: Fork f1: Fork p0: Phil eating

When p0 is eating, eating => left and right is triggered Entails(p0) = { f0 , f1 }

f0: Fork f1: Fork p0: Phil !eating

Example

When p0 is !eating, eating => left and right is cancelled Entails(p0) = { }

slide-37
SLIDE 37

Laser 2005 - Summer School on Software Engineering 37

Concept: Realm

♦ Realm(τ ): Data space of a process (thread) τ

– Set of units to which τ has (exclusive) access – An attempt by τ to reference a unit not in Realm(τ ) is “illegal” (raises a realm-boundary exception) – Terminology: τ holds the units in its realm

♦ Initially, τ holds just a process root unit, denoted Root(τ ) ♦ Suppliers are migrated among realms as processes

– execute operations that change the entailments of the units that they hold – return from invocations of methods on units that they hold but that are not entailed by other units that they hold

no longer need

slide-38
SLIDE 38

Laser 2005 - Summer School on Software Engineering 38

Terminology

For a process τ : ♦ Stack(τ ) is the set of units satisfying

– u ∈ Stack(τ ) if and only if τ is “in” an invocation of one of u’s methods

♦ Needs(τ ) is the smallest set of units satisfying

– Stack(τ ) ⊆ Needs(τ ) and – u ∈ Needs(τ ) implies Entails(u) ⊆ Needs(τ ), for all units u

♦ Realm(τ ) is complete if Realm(τ ) = Needs(τ ) For a unit u : ♦ u’s contract is negotiated if, for all processes τ , u ∈ Realm(τ ) implies Entails(u) ⊆ Realm(τ ) It follows that Realm(τ ) is complete if and only if:

– Process τ holds all units in Stack(τ ) – The contracts of all units that τ holds are negotiated – Realm(τ ) is minimal with respect to these properties

slide-39
SLIDE 39

Laser 2005 - Summer School on Software Engineering 39

♦ If pj is the root unit of process τj and Stack(τ ) contains only pj while pj is !eating: ♦ All contracts are negotiated ♦ All realms are complete

left p2: Phil !eating f0: Fork right right left right left ContractPHIL = { eating => left and right } Convention: We use shading to show realms f1: Fork p1: Phil !eating f2: Fork p0: Phil eating

Needs(τ0 ) = { p0 , f0 , f1 } Needs(τ1 ) = { p1 } Needs(τ2 ) = { p2 }

Example: Realms

slide-40
SLIDE 40

Laser 2005 - Summer School on Software Engineering 40

left p2: Phil eating f0: Fork right right left right left ContractPHIL = { eating => left and right } f1: Fork p1: Phil !eating f2: Fork p0: Phil eating

♦ Now, τ2 also needs f0 and f2 ♦ All contracts except p2’s are negotiated ♦ All realms except τ2’s are complete Convention: We show complete realms in green, incomplete realms in red

Example: Realms

slide-41
SLIDE 41

Laser 2005 - Summer School on Software Engineering 41

Hygienic philosophers: The “get” method of a fork may invoke the “wipe” method of a shared (self-sterilizing!) rag

ContractPHIL = { eating => left and right } ContractFORK = { dirty => rag } left p2: Phil !eating f0: Fork dirty right right left left f1: Fork dirty p1: Phil !eating f2: Fork dirty p0: Phil !eating r0: Rag rag rag right rag

Example: Realms

slide-42
SLIDE 42

Laser 2005 - Summer School on Software Engineering 42

left p2: Phil eating f0: Fork dirty right right left left f1: Fork dirty p1: Phil !eating f2: Fork dirty p0: Phil eating r0: Rag rag rag rag right

♦ Unit p2’s contract is not negotiated ♦ Contracts of all other units are negotiated ♦ Realm( τ0 ) is complete ♦ Realm( τ1 ) is complete ♦ Realm( τ2 ) is incomplete

Example: Realms

ContractPHIL = { eating => left and right } ContractFORK = { dirty => rag }

slide-43
SLIDE 43

Laser 2005 - Summer School on Software Engineering 43

Concept: Contract Negotiation

♦ The run-time system

– Migrates units among realms – Blocks processes whose realms are not complete

♦ In doing so, it guarantees:

– A process executes only when its realm is complete – A unit that a process holds is migrated only when the process no longer needs it – Realms are pairwise disjoint – Realms are “minimal”

slide-44
SLIDE 44

Laser 2005 - Summer School on Software Engineering 44

Contract Negotiation

♦ An operation is realm-affecting if it

– modifies a condition variable or a unit variable – causes the return of a method of a unit that is held by a process τ but that is not entailed by any unit held by τ

♦ When executed by process τ , a realm-affecting

  • peration in a unit u

– Can cause Needs(τ ) to change – Terminology: u is the witness unit

♦ Thus, any affected contracts must be renegotiated

– Realm contraction: Units that are no longer needed are migrated out of the realm – Realm completion: Units that are (newly) needed are atomically migrated into the realm – The process blocks if some needed unit is in another realm

no longer in Needs(t )

slide-45
SLIDE 45

Laser 2005 - Summer School on Software Engineering 45

Example: Contract negotiation

left p2: Phil !eating f0: Fork right right left right left f1: Fork p1: Phil !eating f2: Fork p0: Phil !eating left p2: Phil !eating f0: Fork right left right left right f1: Fork p1: Phil !eating f2: Fork p0: Phil eating

slide-46
SLIDE 46

Laser 2005 - Summer School on Software Engineering 46

Example: Contract negotiation

left p2: Phil !eating f0: Fork right left right left right f1: Fork p1: Phil !eating f2: Fork p0: Phil eating left p2: Phil eating f0: Fork right left right left right f1: Fork p1: Phil !eating f2: Fork p0: Phil eating

slide-47
SLIDE 47

Laser 2005 - Summer School on Software Engineering 47

Example: Contract negotiation

left p2: Phil eating f0: Fork right left right left right f1: Fork p1: Phil !eating f2: Fork p0: Phil eating left p2: Phil eating f0: Fork right right left right left f1: Fork p1: Phil !eating f2: Fork p0: Phil !eating

slide-48
SLIDE 48

Laser 2005 - Summer School on Software Engineering 48

left p2: Phil !eating f0: Fork dirty right left right left f1: Fork dirty p1: Phil !eating f2: Fork dirty p0: Phil !eating r0: Rag ContractPHIL = { eating => left and right } ContractFORK = { dirty => rag } rag rag rag

Example: Contract Negotiation

left p2: Phil !eating f0: Fork dirty right left left right f1: Fork dirty p1: Phil !eating f2: Fork dirty p0: Phil eating r0: Rag rag rag rag right right

slide-49
SLIDE 49

Laser 2005 - Summer School on Software Engineering 49

left p2: Phil !eating f0: Fork !dirty right left left right f1: Fork dirty p1: Phil !eating f2: Fork dirty p0: Phil eating r0: Rag rag rag rag left p2: Phil !eating f0: Fork dirty right left left f1: Fork dirty p1: Phil !eating f2: Fork dirty p0: Phil eating r0: Rag rag rag rag right right right ContractPHIL = { eating => left and right } ContractFORK = { dirty => rag }

Example: Contract Negotiation

slide-50
SLIDE 50

Laser 2005 - Summer School on Software Engineering 50

left p2: Phil !eating f0: Fork !dirty right left left right f1: Fork !dirty p1: Phil !eating f2: Fork dirty p0: Phil eating rag rag left p2: Phil !eating f0: Fork !dirty right left left f1: Fork dirty p1: Phil !eating f2: Fork dirty p0: Phil eating r0: Rag rag rag rag r0: Rag rag right right right ContractPHIL = { eating => left and right } ContractFORK = { dirty => rag }

Example: Contract Negotiation

slide-51
SLIDE 51

Laser 2005 - Summer School on Software Engineering 51

left p2: Phil eating f0: Fork !dirty right left left right f1: Fork !dirty p1: Phil !eating f2: Fork dirty p0: Phil eating rag rag left p2: Phil !eating f0: Fork !dirty right left left f1: Fork !dirty p1: Phil !eating f2: Fork dirty p0: Phil eating rag rag r0: Rag rag r0: Rag rag right right right ContractPHIL = { eating => left and right } ContractFORK = { dirty => rag }

Example: Contract Negotiation

slide-52
SLIDE 52

Laser 2005 - Summer School on Software Engineering 52

left p2: Phil eating f0: Fork !dirty right left right left f1: Fork !dirty p1: Phil !eating f2: Fork dirty p0: Phil !eating rag rag left p2: Phil eating f0: Fork !dirty right left left f1: Fork !dirty p1: Phil !eating f2: Fork dirty p0: Phil eating rag rag r0: Rag rag r0: Rag rag right right right ContractPHIL = { eating => left and right } ContractFORK = { dirty => rag }

Example: Contract Negotiation

slide-53
SLIDE 53

Laser 2005 - Summer School on Software Engineering 53

Overview of lecture series

♦ Background ♦ Introduction to Szumo

– Key concepts – Revisit concurrency problems

♦ Case study ♦ Semantic and implementation details ♦ Related concurrency models ♦ Ongoing and future work

slide-54
SLIDE 54

Laser 2005 - Summer School on Software Engineering 54

Revisit: Problems

♦ Interleaving of concurrency logic with “functional” logic ♦ Undocumented rights and responsibilities ♦ Failure to “protect” critical region ♦ Potential for deadlock and starvation

slide-55
SLIDE 55

Laser 2005 - Summer School on Software Engineering 55

Recall: Interleaving of concurrency logic with “functional” logic

Class Fork { private boolean taken = false; private id; . . . synchronized void put(Phil p) { …println( p.toString() + “ put down ” + this.toString(); taken = false; notifyAll(); } synchronized void get(Phil p) { while (taken) wait (); taken = true; …println( p.toString() + “ picked up ” + this.toString(); } . . . synchronization class FORK . . . feature id: INTEGER; . . . put(p: PHIL) is do print_string(p.to_string + “ put down ” + to_string + “%N”) end -- put get(p: PHIL) is do print_string(p.to_string + “ picked up ” + to_string + “%N”) end -- get end -- FORK

VS.

slide-56
SLIDE 56

Laser 2005 - Summer School on Software Engineering 56

Class Phil extends Thread { private Fork left; private Fork right; . . . public void run( ) { while (true) { think(); left.get(this); right.get(this); eat(); right.put(this); left.put(this); } } . . . } synchronization class PHIL . . . feature left, right: FORK eating: BOOLEAN . . . start is do from until false loop think eating := true left.get(Current); right.get(Current) eat right.put(Current); left.put(Current) eating := false end end -- start concurrency eating => left and rig end -- PHIL

VS.

Interleaving of concurrency logic with “functional” logic

slide-57
SLIDE 57

Laser 2005 - Summer School on Software Engineering 57

Szumo reduces interleaving of concurrency logic and “functional”logic

Similar to aspect-oriented program:

♦ Assignments to condition variables are analogous to “point cuts” ♦ Concurrency clause is analogous to “advice” ♦ Facilitates distinguishing synchronization code from functional code ♦ Run-time system “weaves in” the low level logic to acquire suppliers while avoiding deadlock and starvation

slide-58
SLIDE 58

Laser 2005 - Summer School on Software Engineering 58

Recall: Undocumented rights and responsibilities

In Szumo: ♦ Clients’ rights are made explicit in contracts

– e.g., eating => left and right

♦ Responsibility for ensuring mutual exclusion is assumed by the run-time system (not the supplier)

slide-59
SLIDE 59

Laser 2005 - Summer School on Software Engineering 59

Recall: Failure to “protect” critical regions

In Szumo: ♦ E.g, flawed contract or error in updating a condition variable ♦ Will cause a realm-boundary exception at run- time, not a data race ♦ Are observable and easier to isolate

slide-60
SLIDE 60

Laser 2005 - Summer School on Software Engineering 60

Recall: Potential for starvation

Fairness is built into the contract negotiation algorithms

♦ Negotiations are prioritized by their “age” (with modifications for deadlock avoidance) ♦ No better (or worse) than most other concurrency models in preventing starvation

slide-61
SLIDE 61

Laser 2005 - Summer School on Software Engineering 61

Recall: Potential for deadlock

♦ Root cause: Critical region incrementally acquires multiple suppliers ♦ In Szumo: “Atomic” acquisition of multiple suppliers is automated

– Contraction phase releases units that are no longer entailed – Completion phase

  • Expand a realm only when the realm can be completed
  • Guarantee: If there exist realms that can be completed, then

some realm will be completed

slide-62
SLIDE 62

Laser 2005 - Summer School on Software Engineering 62

Caveat: Szumo does not eliminate the possibility of deadlock

♦ Recall the correctness criteria for realm negotiation:

– A process executes only when its realm is complete – A unit that a process holds is migrated only when the process no longer needs it – Realms are pairwise disjoint – Realms are “minimal”

♦ A flawed unit design can admit configurations in which no realm can be completed without violating these correctness criteria

slide-63
SLIDE 63

Laser 2005 - Summer School on Software Engineering 63

Example: Design does not countenance deadlock

s1: S s0: S

direct direct indirect indirect

c0: C s1: S s0: S c1: C inCR inCR

direct indirect direct indirect

c0: C s1: S s0: S c1: C inCR inCR

direct indirect direct indirect

ContractC = { inCR => direct } ContractS = { indirect } c0: C !inCR c1: C !inCR

slide-64
SLIDE 64

Laser 2005 - Summer School on Software Engineering 64

Example: design does countenance deadlock

c0: C s1: S s0: S c1: C !inCCR !inCCR

direct indirect direct indirect CCC = { inCCR => direct } CCS = { inSCR => indirect }

!inSCR !inSCR c0: C s1: S s0: S c1: C inCCR inCCR

direct indirect direct indirect

!inSCR !inSCR c0: C s1: S s0: S c1: C inCCR inCCR

direct indirect direct indirect

inSCR inSCR

feature foo is inCCR := true if direct.ok then do direct.foobar . . . end -- if inCCR := false end -- foo

slide-65
SLIDE 65

Laser 2005 - Summer School on Software Engineering 65

♦ Modules declare data access requirements via synchronization contracts ♦ Run-time system negotiates contracts among concurrent threads and flags non-conforming accesses ♦ Benefits:

– Encapsulate/separate mutual-exclusion logic from functional code – Compose to yield global effects – Contracts are negotiated/enforced at run-time

Summary of Szumo

slide-66
SLIDE 66

Laser 2005 - Summer School on Software Engineering 66

Maturity of Szumo

To date: ♦ Extended an OO language (Eiffel) with synchronization contracts ♦ Applied Szumo Eiffel to textbook examples ♦ Performed an empirical performance evaluation ♦ Performed a realistic case study