Docsity

Model Checking and Verification of Concurrent Programs in Maude - Prof. Jose Meseguer, Study notes of Computer Science

Partial preview of the text

Download Model Checking and Verification of Concurrent Programs in Maude - Prof. Jose Meseguer and more Study notes Computer Science in PDF only on Docsity!

Program Verification:

Lecture 23

Jos´

e Meseguer

Computer Science Department

University of Illinois at Urbana-Champaign

Model Checking

TOK-RING

Consider the following

TOK-RING

module,

(fth NZNAT* is

protecting NAT .op * : -> NzNat. endfth) (fmod NAT/(N :: NZNAT*) is

sort Nat/(N) .op ‘[_‘] : Nat -> Nat/(N) .op + : Nat/(N) Nat/(N) -> Nat/(N) .op * : Nat/(N) Nat/(N) -> Nat/(N) .vars I J : Nat .ceq [I] = [I rem *] if I >= * .eq [I] + [J] = [I + J] .eq [I] * [J] = [I * J]. endfm)

Model Checking

TOK-RING

(II)

The

TOK-RING

module satisfies the following two properties:

mutual exclusion

, and

guaranteed reentrance

, that is:

◦

each process eventually reaches its critical section,and

◦

it does so again after

2

×

n

steps.

There isn’t a single LTL formula stating each of theseproperties: they are

parametric

on

n

. However, in Full

Maude we can specify these properties by parametic formuladefinitions as follows:

Model Checking

TOK-RING

(III)

(omod CHECK-TOK-RING(N :: NZNAT*) is

inc TOK-RING(N) .inc MODEL-CHECKER .subsort Configuration < State .op inCrit : Nat/(N) -> Prop .op twoInCrit : -> Prop .var

I : Nat.

vars X Y : Nat/(N) .var

C : Configuration.

var

F : Formula.

eq < X : Proc | mode : critical > C |= inCrit(X) = true .eq < X : Proc | mode : critical > < Y : Proc | mode : critical > C

|= twoInCrit = true.

Model Checking

TOK-RING

(IV)

We cannot model check these properties directly in their parameterized

form. However, for each nozero value

n

we

can check the corresponding

instance

of these properties.

For example, for

n

= 5

we define in Full Maude the

view

(view 5 from NZNAT* to NAT is

op * to term 5. endv)

Then we can model check the mutual exclusion property for5 processes as follows: (red in CHECK-TOK-RING(5) : modelCheck(init,[] ~ twoInCrit) .)result Bool :

true

Model Checking

TOK-RING

(V)

In the same way, we can model check the

guaranteed

reentrance

property for

n

= 5

by giving to Full Maude the

command, (red in CHECK-TOK-RING(5) : modelCheck(init,[] guaranteedReentrance) .)result Bool :

true

Verification of Concurrent Imperative Programs (II)

What should the analogous situation be in the case of concurrent

imperative programs? We should of course

specify the

semantics

of a concurrent imperative language

L

as a

rewrite theory

R

( L

)^

(in fact, a Maude system module).

Then, the correctness of imperative programs in

L

can be

reduced to

proving inductive properties

satisfied by the

initial model

T

Reach

(R

(L

))

. If such properties are specified in

temporal logic

, then we can use methods such as model

checking or deductive proof.We can illustrate this general method by definig therewriting logic semantics of a simple parallel language called PARALLEL

The Rewriting Semantics of

PARALLEL

*** A simple parallel language and its rewriting logic semantics.*** Extends an even simpler language presented in ‘‘The Maude LTL*** Model Checker’’ by Eker, Meseguer, and Sridaranarayanan,*** in Proc. WRLA’02, ENTCS Vol. 71, Elsevier, 2002.fmod MEMORY is inc INT.

inc QID.

sorts Memory Bool? Int? .subsorts Bool < Bool?. subsorts Int < Int? .op null : -> Int? .op none : -> Memory .op __ : Memory Memory -> Memory [assoc comm id: none] .op [,] : Qid Int? -> Memory .op in : Qid Memory -> Bool? .var Q : Qid.

var M : Memory.

var N? : Int?.

eq null + N? = null .eq null * N? = null .eq Q in [Q,N?] M = true. endfm

fmod EXPRESSION is

inc MEMORY .sort Expression .subsorts Qid Int? < Expression .op +’ : Expression Expression -> Expression [ctor] .op *’ : Expression Expression -> Expression [ctor] .op eval : Expression Memory -> Int? .var Q : Qid .var M : Memory .vars N N’ : Int .var N? : Int? .vars E E’ : Expression .eq eval(N?, M) = N? .eq eval(Q, [Q, N?] M) = N? .ceq eval(Q,M) = null if Q in M =/= true .eq eval(E +’ E’, M) = eval(E,M) + eval(E’,M) .eq eval(E *’ E’, M) = eval(E,M) * eval(E’,M). endfm

***(Syntax for a trival sequential language.

We allow abstracting

out program fragments as elements of sorts LoopingUserStatement andUserStatement.

Elements of sort LoopingUserStatement abstract out

potentially nonterminating program fragments, whereas elements of sortUserStatement but not of sort LoopingUserStatement abstract out terminatingprogram fragments.)fmod SEQUENTIAL is

inc TESTS .inc EXPRESSION .sorts UserStatement LoopingUserStatement Program .subsort LoopingUserStatement < UserStatement < Program .op skip : -> Program .op ; : Program Program -> Program [prec 61 assoc id: skip] .op := : Qid Expression -> Program .op if_then_fi : Test Program -> Program .op while_do_od : Test Program -> Program .op repeat_forever : Program -> Program. endfm

The Rewriting Semantics of

PARALLEL

(III)

mod PARALLEL is

inc SEQUENTIAL .inc TESTS .sorts Pid Process Soup MachineState .subsort Process < Soup .subsort Int < Pid .op [,] : Pid Program -> Process .op empty : -> Soup .op | : Soup Soup -> Soup [prec 61 assoc comm id: empty] .op {,,_} : Soup Memory Pid -> MachineState.

vars P R : Program .var S : Soup .var U : UserStatement .var L : LoopingUserStatement .vars I J : Pid .var M : Memory .var Q : Qid .vars N? X? : Int? .var T : Test .var E : Expression .rl {[I, U ; R] | S, M, J} => {[I, R] | S, M, I} .rl {[I, L ; R] | S, M, J} => {[I, L ; R] | S, M, I} .rl {[I, (Q := E) ; R] | S, [Q, X?] M, J} =>

{[I, R] | S, [Q,eval(E,[Q, X?] M)] M, I}.

crl {[I, (Q := E) ; R] | S, M, J} =>

{[I, R] | S, [Q,eval(E,M)] M, I} if Q in M =/= true.

Dekker’s Mutex Algorithm

One of the earliest correct solutions to the mutual exclusionproblem was given by Dekker with his algorithm. Thealgorithm assumes processes that execute concurrently on ashared memory machine and communicate with each otherthrough shared variables.There are two processes,

p

and

p

. Process 1 sets a

Boolean variable

c

to 1 to indicate that it wishes to enter

its critical section. Process

p

does the same with variable

c

. If one process, after setting its variable to 1 finds that

the variable of its competitor is 0, then it enters its criticalsection rightaway. In case of a tie (both variables set to 1)the tie is broken using a variable

turn

that takes values in

{

1

,^ 2

}

Dekker’s Mutex Algorithm (II)

The code of process 1 in

PARALLEL

is as follows,

repeat

c1 := 1 ;while c2 = 1 do

if turn = 2 then

c1 := 0 ;while turn = 2 do skip od ;c1 := 1 fi od ;crit ;turn := 2 ;c1 := 0 ;rem forever.