CONCURRENCY, INTUITION AND FORMAL VERIFICATION: YES, WE CAN! - - PowerPoint PPT Presentation

concurrency intuition and formal verification yes we can
SMART_READER_LITE
LIVE PREVIEW

CONCURRENCY, INTUITION AND FORMAL VERIFICATION: YES, WE CAN! - - PowerPoint PPT Presentation

CONCURRENCY, INTUITION AND FORMAL VERIFICATION: YES, WE CAN! BEN-ARIS TWIN-PROCESS CONUNDRUM MATT PEDERSEN & PETER WELCH Communicating Process Architectures 2017 Fringe The Problem Professor Ben-Ari used the problem for a decade


slide-1
SLIDE 1

CONCURRENCY, INTUITION AND FORMAL VERIFICATION: YES, WE CAN! BEN-ARI’S TWIN-PROCESS CONUNDRUM

MATT PEDERSEN & PETER WELCH

Communicating Process Architectures 2017 Fringe

slide-2
SLIDE 2

The Problem

¨ Professor Ben-Ari used the problem for a decade

(described in “A model checking primer”)

slide-3
SLIDE 3

The Problem

¨ 2 Processes P and Q run concurrently ¨ Both update a shared variable n (initially 0) ten

  • times. Each update is as follows:

¤ Read n ¤ Increment it locally ¤ Write n back

slide-4
SLIDE 4

Pseudo Code

integer n = 0; process P integer regP = 0; do 10 times load n into regP increment regP store regP into n end process Q integer regQ = 0; do 10 times load n into regQ increment regQ store regQ into n end

slide-5
SLIDE 5

Possible values for n?

slide-6
SLIDE 6

The Problem

¨ Professor Ben-Ari used the problem for a decade ¨ Told his students the value would be between 10

and 20

slide-7
SLIDE 7

The Problem

¨ Professor Ben-Ari used the problem for a decade. ¨ Told his students the value would be between 10

and 20.

¨ One day a student of his got the value 9 ! ¨ Actually any number between 2 and 20 is possible.

slide-8
SLIDE 8

What do we do now?

¨ Start by proving that we can get 2, and how.

Problem CSP FDR Trace Assertion

slide-9
SLIDE 9

A CSP Model

¨ Channels:

channel load, store : {0..20}
 channel kill

¨ Increment function:

inc (x) = 
 if x >= 20 then 
 20 
 else 
 x + 1

slide-10
SLIDE 10

A CSP Model

¨ The process itself (P and Q):

P = ; x:<0..9> @ load ? n à 
 store ! inc (n) à 
 SKIP

slide-11
SLIDE 11

A CSP Model

¨ A process representing n:

Var (n) =
 store ? x à Var (x)
 []
 load ! n à Var (n)
 []
 kill à SKIP -- terminate

slide-12
SLIDE 12

A CSP Model

¨ A checking process

PP_check =
 (P ||| P);
 load ? n à
 if n == 2 then STOP
 else kill -> SKIP

slide-13
SLIDE 13

A CSP Model

¨ The entire system:

System =
 PP_check
 [| {| load, store, kill |} |]
 Var (0)

slide-14
SLIDE 14

Analysis of the Model

PP_check =
 (P ||| P);
 load ? n à
 if n == 2 then STOP
 else kill -> SKIP

¨ If this process always terminates the value of n

cannot be 2.

¨ assert SKIP [FD= System \ Events


checks if System always terminates.

slide-15
SLIDE 15

Analysis of the Model

slide-16
SLIDE 16

Trace leading to n=2

slide-17
SLIDE 17

Time P Q n Load 0 1 Load 0 2 Store 1 1 3 Load 1 1 4 Store 2 2 5-16 … 2-8 17 Load 8 8 18 Store 9 9 19 Store 1 1 20 Load 1 1 21 Load 1 1 22 Store 2 2 23-36 … 2-9 37 Load 9 9 38 Store 10 10 39 Store 2 2

slide-18
SLIDE 18

Aside

¨ Did the STOP cause lack of termination?

PP_check =
 (P ||| P);
 load ? n à
 if n == 2 then STOP
 else kill -> SKIP

slide-19
SLIDE 19

Aside

¨ Did the STOP cause lack of termination? ¨ Consider this:

PP_no_check = (P ||| P); 
 kill à SKIP

¨ Terminates just fine

slide-20
SLIDE 20

Correct Behaviour

¨ Introduce a mutex:

channel wait, signal
 
 Mutex =
 wait à signal à Mutex
 []
 kill à SKIP

slide-21
SLIDE 21

Add use of mutex to P process

¨ Introduce the mutex into the P process (now called

P’): P’ = ; x:<0..9> @
 wait à
 load ? N à store ! inc (n) à
 signal à SKIP

slide-22
SLIDE 22

Wire up the system

¨ Lets wire it all up (2 processes and a check):

PP_check’ = (P’ ||| P’);
 load ? n à
 if n != 20 then STOP
 else kill à SKIP


slide-23
SLIDE 23

Wire up the system

¨ Wire up the entire system and add the mutex:

SYSTEM’ =
 PP_check’
 [| {| load, store, kill |} |]
 Var (0)
 
 SAFE_SYSTEM =
 SYSTEM’
 [| {| wait, signal, kill |} |]
 Mutex

slide-24
SLIDE 24

FDR check the SAFE_SYSTEM

¨ Check if the SAFE_SYSTEM terminates:

assert SKIP [FD= SAFE_SYSTEM \ Events

¨ It does!

¤ 20 is the only value the variable can have upon termination.

slide-25
SLIDE 25
  • ccam-pi demo