An Algorithmic Framework for Synthesis of Concurrent Programs E. - - PowerPoint PPT Presentation

an algorithmic framework for synthesis of concurrent
SMART_READER_LITE
LIVE PREVIEW

An Algorithmic Framework for Synthesis of Concurrent Programs E. - - PowerPoint PPT Presentation

Preliminaries Solution framework Correctness Conclusion An Algorithmic Framework for Synthesis of Concurrent Programs E. Allen Emerson and Roopsha Samanta The University of Texas at Austin Oct 12, 2011 E. Allen Emerson and Roopsha Samanta


slide-1
SLIDE 1

Preliminaries Solution framework Correctness Conclusion

An Algorithmic Framework for Synthesis of Concurrent Programs

  • E. Allen Emerson and Roopsha Samanta

The University of Texas at Austin

Oct 12, 2011

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 1 / 23

slide-2
SLIDE 2

Preliminaries Solution framework Correctness Conclusion

Let’s begin with an example

Reader P1 Writer P2

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 2 / 23

slide-3
SLIDE 3

Preliminaries Solution framework Correctness Conclusion

Let’s begin with an example

Reader P1 Writer P2 P1() { while(true) { Execute code region

IDLE1;

Execute code region

TRY1;

Execute code region

CS1;

}} P2() { while(true) { Execute code region

IDLE2;

Execute code region

TRY2;

Execute code region

CS2;

}}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 2 / 23

slide-4
SLIDE 4

Preliminaries Solution framework Correctness Conclusion

Let’s begin with an example

Reader P1 Writer P2 P1() { while(true) { Execute code region

IDLE1;

Execute code region

TRY1;

Execute code region

CS1;

}} P2() { while(true) { Execute code region

IDLE2;

Execute code region

TRY2;

Execute code region

CS2;

}} Mutual exclusion: AG(¬(CS1 ∧ CS2)). Absence of starvation for reader P1, provided writer P2 remains idle: AG(TRY1 ⇒ AF(CS1 ∨ ¬IDLE2)). Absence of starvation for writer: AG(TRY2 ⇒ AF CS2). Priority of writer over reader for outstanding requests to enter the critical section: AG((TRY1 ∧ TRY2) ⇒ A[TRY1 U CS2]).

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 2 / 23

slide-5
SLIDE 5

Preliminaries Solution framework Correctness Conclusion

Let’s begin with an example

Reader P1 Writer P2 P1() { while(true) { Execute code region

IDLE1;

Execute code region

TRY1;

Execute code region

CS1;

}} P2() { while(true) { Execute code region

IDLE2;

Execute code region

TRY2;

Execute code region

CS2;

}}

φ

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 2 / 23

slide-6
SLIDE 6

Preliminaries Solution framework Correctness Conclusion

Let’s begin with an example

Reader P1 Writer P2

| =

φ

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 2 / 23

slide-7
SLIDE 7

Preliminaries Solution framework Correctness Conclusion

Problem definition

Given unsynchronized P1, P2 and φ such that P1 P2 | = φ, automatically generate P1, P2 such that P1 P2 | = φ.

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 3 / 23

slide-8
SLIDE 8

Preliminaries Solution framework Correctness Conclusion

Our solution

main() { P1() P2(); } P1() { while(true) { Execute code region

IDLE1;

Execute code region

TRY1;

Execute code region

CS1;

}} P2() { while(true) { Execute code region

IDLE2;

Execute code region

TRY2;

Execute code region

CS2;

}}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 4 / 23

slide-9
SLIDE 9

Preliminaries Solution framework Correctness Conclusion

Our solution

main() { boolean idle1:=1, try1:=0, cs1:=0, idle2:=1, try2:=0, cs2:=0; lock l, condition variables cvcs1 , cvcs2 ; P1() P2(); } P1() { while(true) { Execute code region

I D L E1;

lock(l) { idle1, try1 := 0,1; notify(cvcs2 ); } Execute code region

T R Y1;

lock(l) { while (!idle2) wait(cvcs1 ,l); try1, cs1 := 0,1; } Execute code region

C S1;

lock(l) { cs1, idle1 := 0,1; notify(cvcs2 ); }}} P2() { while(true) { Execute code region

I D L E2;

lock(l) { idle2, try2 := 0,1; } Execute code region

T R Y2;

lock(l) { while (!(idle1 ∨ try1)) wait(cvcs2 ,l); try2, cs2 := 0,1; } Execute code region

C S2;

lock(l) { cs2, idle2 := 0,1; notify(cvcs1 ); }}}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 4 / 23

slide-10
SLIDE 10

Preliminaries Solution framework Correctness Conclusion

Our solution

Reader P1 Writer P2

| =

φ

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 5 / 23

slide-11
SLIDE 11

Preliminaries Solution framework Correctness Conclusion

Outline

Preliminaries Solution framework Correctness Conclusion

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 6 / 23

slide-12
SLIDE 12

Preliminaries Solution framework Correctness Conclusion

Motivation

Problem: Shared memory concurrent programs

Ubiquitous Hard to write Harder to verify (safety, liveness)

Proposal: Automatically synthesize synchronization code

Only write unsynchronized skeletons Correct-by-construction synchronization code No further verification needed

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 7 / 23

slide-13
SLIDE 13

Preliminaries Solution framework Correctness Conclusion

Motivation

Problem: Shared memory concurrent programs

Ubiquitous Hard to write Harder to verify (safety, liveness)

Proposal: Automatically synthesize synchronization code

Only write unsynchronized skeletons Correct-by-construction synchronization code No further verification needed

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 7 / 23

slide-14
SLIDE 14

Preliminaries Solution framework Correctness Conclusion

Motivation

Problem: Shared memory concurrent programs

Ubiquitous Hard to write Harder to verify (safety, liveness)

Proposal: Automatically synthesize synchronization code

Only write unsynchronized skeletons Correct-by-construction synchronization code No further verification needed

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 7 / 23

slide-15
SLIDE 15

Preliminaries Solution framework Correctness Conclusion

Motivation

Problem: Shared memory concurrent programs

Ubiquitous Hard to write Harder to verify (safety, liveness)

Proposal: Automatically synthesize synchronization code

Only write unsynchronized skeletons Correct-by-construction synchronization code No further verification needed

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 7 / 23

slide-16
SLIDE 16

Preliminaries Solution framework Correctness Conclusion

Groundwork

Unsynchronized skeletons → state-machines Code regions → states (atomic propositions) Control-flow → transition relation

P1() { while(true) { Execute code region

IDLE1;

Execute code region

TRY1;

Execute code region

CS1;

}}

IDLE1 TRY1 CS1

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 8 / 23

slide-17
SLIDE 17

Preliminaries Solution framework Correctness Conclusion

Groundwork

Unsynchronized skeletons → state-machines Code regions → states (atomic propositions) Control-flow → transition relation Interleaved, asynchronous computation CTL specification

Safety: AG(¬(CS1 ∧ CS2)) Liveness: AG(TRY2 ⇒ AF CS2)

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 8 / 23

slide-18
SLIDE 18

Preliminaries Solution framework Correctness Conclusion

Recall problem definition

Given skeletons P1, P2 and φ such that P1 P2 | = φ, automatically generate P1, P2 such that P1 P2 | = φ.

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 9 / 23

slide-19
SLIDE 19

Preliminaries Solution framework Correctness Conclusion

Solution framework

Step 1: Synthesize synchronization skeletons, Ps

1, Ps 2

High-level synchronization actions

Guarded commands

Ps

1 Ps 2 |

= φ

Step 2: Mechanically translate Ps

1, Ps 2 into P1, P2

Low-level synchronization code

Monitors (wait and notify), mutex locks

Correctness-preserving translation, i.e., P1 P2 | = φ

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 10 / 23

slide-20
SLIDE 20

Preliminaries Solution framework Correctness Conclusion

Solution framework

Step 1: Synthesize synchronization skeletons, Ps

1, Ps 2

High-level synchronization actions

Guarded commands

Ps

1 Ps 2 |

= φ

Step 2: Mechanically translate Ps

1, Ps 2 into P1, P2

Low-level synchronization code

Monitors (wait and notify), mutex locks

Correctness-preserving translation, i.e., P1 P2 | = φ

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 10 / 23

slide-21
SLIDE 21

Preliminaries Solution framework Correctness Conclusion

Step 1: High-level synchronization

[EmersonClarke82] Reader P1:

IDLE1 TRY1 CS1

Writer P2:

IDLE2 TRY2 CS2

φ

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 11 / 23

slide-22
SLIDE 22

Preliminaries Solution framework Correctness Conclusion

Step 1: High-level synchronization

M | = phi:

IDLE1 IDLE2 TRY1 IDLE2 IDLE1 TRY2 CS1 IDLE2 TRY1 TRY2 IDLE1 CS2 CS1 TRY2 TRY1 CS2

1 2 1 2 1 2 2 2 1 1 2 1 2

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 11 / 23

slide-23
SLIDE 23

Preliminaries Solution framework Correctness Conclusion

Step 1: High-level synchronization

Reader Ps

1:

IDLE1 TRY1 CS1 IDLE2?

Writer Ps

2:

IDLE2 TRY2 CS2 IDLE1 ∨ TRY1?

Ps

1 Ps 2 |

= φ

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 11 / 23

slide-24
SLIDE 24

Preliminaries Solution framework Correctness Conclusion

Step 2: Low-level synchronization

Obtain P1, P2 from Ps

1, Ps 2

Monitors (wait and notify), mutex locks P1 P2 | = φ

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 12 / 23

slide-25
SLIDE 25

Preliminaries Solution framework Correctness Conclusion

Step 2: Coarse-grained synchronization

Declare Boolean shared variables Declare (single) lock and condition variables

main() { boolean idle1:=1, try1:=0, cs1:=0, idle2:=1, try2:=0, cs2:=0; lock l, condition variables cvcs1, cvcs2; Pc

1() Pc 2();

}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 13 / 23

slide-26
SLIDE 26

Preliminaries Solution framework Correctness Conclusion

Step 2: Coarse-grained synchronization

Declare Boolean shared variables Declare (single) lock and condition variables

main() { boolean idle1:=1, try1:=0, cs1:=0, idle2:=1, try2:=0, cs2:=0; lock l, condition variables cvcs1, cvcs2; Pc

1() Pc 2();

}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 13 / 23

slide-27
SLIDE 27

Preliminaries Solution framework Correctness Conclusion

Step 2: Coarse-grained synchronization

Compile each guarded command in Ps

1, Ps 2 into a

coarse-grained synchronization region

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 14 / 23

slide-28
SLIDE 28

Preliminaries Solution framework Correctness Conclusion

Step 2: Coarse-grained synchronization

TRY1 CS1 IDLE2?

Execute

TRY1;

lock(l) { while (!idle2) wait(cvcs1,l); try1, cs1 := 0,1; } Execute

CS1;

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 14 / 23

slide-29
SLIDE 29

Preliminaries Solution framework Correctness Conclusion

Step 2: Coarse-grained synchronization

main() { boolean idle1:=1, try1:=0, cs1:=0, idle2:=1, try2:=0, cs2:=0; lock l, condition variables cvcs1 , cvcs2 ; Pc

1() Pc 2();

} Pc

1() {

while(true) { Execute code region

I D L E1;

lock(l) { idle1, try1 := 0,1; notify(cvcs2 ); } Execute code region

T R Y1;

lock(l) { while (!idle2) wait(cvcs1 ,l); try1, cs1 := 0,1; } Execute code region

C S1;

lock(l) { cs1, idle1 := 0,1; notify(cvcs2 ); }}} Pc

2() {

while(true) { Execute code region

I D L E2;

lock(l) { idle2, try2 := 0,1; } Execute code region

T R Y2;

lock(l) { while (!(idle1 ∨ try1)) wait(cvcs2 ,l); try2, cs2 := 0,1; } Execute code region

C S2;

lock(l) { cs2, idle2 := 0,1; notify(cvcs1 ); }}}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 15 / 23

slide-30
SLIDE 30

Preliminaries Solution framework Correctness Conclusion

Step 2: Fine-grained synchronization

Declare Boolean shared variables Declare mutex locks, monitor locks and condition variables

main() { boolean idle1:=1, try1:=0, cs1:=0, idle2:=1, try2:=0, cs2:=0; lock lidle1, ltry1, lcs1, lidle2, ltry2, lcs2; lock lcvcs1, condition variable cvcs1; lock lcvcs2, condition variable cvcs2; Pf

1() Pf 2();

}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 16 / 23

slide-31
SLIDE 31

Preliminaries Solution framework Correctness Conclusion

Step 2: Fine-grained synchronization

Declare Boolean shared variables Declare mutex locks, monitor locks and condition variables

main() { boolean idle1:=1, try1:=0, cs1:=0, idle2:=1, try2:=0, cs2:=0; lock lidle1, ltry1, lcs1, lidle2, ltry2, lcs2; lock lcvcs1, condition variable cvcs1; lock lcvcs2, condition variable cvcs2; Pf

1() Pf 2();

}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 16 / 23

slide-32
SLIDE 32

Preliminaries Solution framework Correctness Conclusion

Step 2: Fine-grained synchronization

Compile each guarded command in Ps

1, Ps 2 into a

fine-grained synchronization region

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 17 / 23

slide-33
SLIDE 33

Preliminaries Solution framework Correctness Conclusion

Step 2: Fine-grained synchronization

TRY1 CS1 IDLE2?

Execute

TRY1;

lock(lcvcs1) { while (!Guardcs1()) wait(cvcs1,lcvcs1); } Execute

CS1;

boolean Guardcs1() { lock((ltry1, lcs1, lidle2) { if (idle2) { try1, cs1 := 0,1; return(true); } else return(false); }}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 17 / 23

slide-34
SLIDE 34

Preliminaries Solution framework Correctness Conclusion

Step 2: Fine-grained synchronization

main() { boolean idle1:=1, try1:=0, cs1:=0, idle2:=1, try2:=0, cs2:=0; lock lidle1 , ltry1 , lcs1 , lidle2 , ltry2 , lcs2 ; lock lcvcs1 , condition variable cvcs1 ; lock lcvcs2 , condition variable cvcs2 ; Pf

1() Pf 2();}

Pc

1() {

while(true) { Execute code region

I D L E1;

lock(lidle1 , ltry1 ) { idle1, try1 := 0,1;} lock(()lcvcs2 ) { notify(cvcs2 );} Execute code region

T R Y1;

lock(lcvcs1 ) { while (!Guardcs1 ()) wait(cvcs1 ,lcvcs1 );} Execute code region

C S1;

lock(lidle1 , lcs1 ) { cs1, idle1 := 0,1;} lock(()lcvcs2 ) { notify(cvcs2 );}}} Pc

2() {

while(true) { Execute code region

I D L E2;

lock(lidle2 , ltry2 ) { idle2, try2 := 0,1;} Execute code region

T R Y2;

lock(lcvcs2 ) { while (!Guardcs2 ()) wait(cvcs2 ,lcvcs2 );} Execute code region

C S2;

lock(lidle2 , lcs2 ) { cs2, idle2 := 0,1;} lock(()lcvcs1 ) { notify(cvcs1 );}}}

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 18 / 23

slide-35
SLIDE 35

Preliminaries Solution framework Correctness Conclusion

Review

What we have so far . . .

Fully algorithmic synthesis of synchronization

Algorithmic front-end for high-level synchronization Algorithmic back-end for low-level synchronization

Coarse and fine-grained synchronization

What’s remaining?

Correctness What properties can we handle?

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 19 / 23

slide-36
SLIDE 36

Preliminaries Solution framework Correctness Conclusion

Review

What we have so far . . .

Fully algorithmic synthesis of synchronization

Algorithmic front-end for high-level synchronization Algorithmic back-end for low-level synchronization

Coarse and fine-grained synchronization

What’s remaining?

Correctness What properties can we handle?

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 19 / 23

slide-37
SLIDE 37

Preliminaries Solution framework Correctness Conclusion

Correspondence Lemmas

[Coarse-grained Correspondence]: Given an ACTL \ X formula φ, Ps

1 Ps 2 |

= φ ⇒ Pc

1 Pc 2 |

= φ. [Fine-grained Correspondence]: Given an ACTL \ X formula φ, Ps

1 Ps 2 |

= φ ⇒ Pf

1 Pf 2 |

= φ.

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 20 / 23

slide-38
SLIDE 38

Preliminaries Solution framework Correctness Conclusion

Correctness

Sound and complete for consistent temporal specifications!

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 21 / 23

slide-39
SLIDE 39

Preliminaries Solution framework Correctness Conclusion

Contributions

Fully algorithmic synthesis of synchronization

Algorithmic front-end for high-level synchronization Algorithmic back-end for low-level synchronization

Coarse and fine-grained synchronization Safety and liveness Sound and complete (for ACTL \ X )

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 22 / 23

slide-40
SLIDE 40

Preliminaries Solution framework Correctness Conclusion

Related Work

Inference of high-level synchronization, guarded commands: [EC82, VYY09] Mapping of high-level to low-level synchronization: [DDHM01, Y-KB02] Lock-inference, locking granularity: [EFJM07, CCG08] Sketching: [S-LRBE05] Open systems [PR89]

  • E. Allen Emerson and Roopsha Samanta

An Algorithmic Framework for Synthesis of Concurrent Programs 23 / 23