You are on page 1of 2

FMCS Lab

EXPERIMENT 2:
Design and develop and run a program in NuSMV to model and solve the Mutual Exclusion problem. Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections. A critical section is a piece of code in which a process or thread accesses a common resource. The critical section by itself is not a mechanism or algorithm for mutual exclusion. A program, process, or thread can have the critical section in it without any mechanism or algorithm which implements mutual exclusion. The following program is an example of asynchronous model. It uses a variable semaphore to implement mutual exclusion between two asynchronous processes. Each process has four states: idle, entering, critical and exiting. The entering state indicates that the process wants to enter its critical region. If the variable semaphore is FALSE, it goes to the critical state, and sets semaphore to TRUE. On exiting its critical region, the process sets semaphore to FALSE again.

PROGRAM:
MODULE main VAR s0: {noncritical, trying, critical}; s1: {noncritical, trying, critical}; turn: boolean; pr0: process prc(s0, s1, turn, 0); pr1: process prc(s1, s0, turn, 1); ASSIGN init(turn) := 0; FAIRNESS !(s0 = critical) --FAIRNESS --!(s1 = critical) SPEC EF((s0 = critical) & (s1 = critical)) SPEC AG((s0 = trying) -> AF (s0 = critical)) M.Tech/Dept. of CSE/B.N.M.I.T.

FMCS Lab SPEC AG((s1 = trying) -> AF (s1 = critical)) SPEC AG((s0 = critical) -> A[(s0 = critical) U (!(s0 = critical) & A[!(s0 = critical) U (s1 = critical)])]) SPEC AG((s1 = critical) -> A[(s1 = critical) U (!(s1 = critical) & A[!(s1 = critical) U (s0 = critical)])]) MODULE prc(state0, state1, turn, turn0) ASSIGN init(state0) := noncritical; next(state0) := case (state0 = noncritical) : {trying,noncritical}; (state0 = trying) & (state1 = noncritical): critical; (state0 = trying) & (state1 = trying) & (turn = turn0): critical; (state0 = critical) : {critical,noncritical}; 1: state0; esac; next(turn) := case turn = turn0 & state0 = critical: !turn; 1: turn; esac; FAIRNESS running

M.Tech/Dept. of CSE/B.N.M.I.T.

You might also like