{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Dining - Model Checking and Testing Classical IPC Problem...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Model Checking and Testing Classical IPC Problem: Dining Philosophers Model Checking – Modeling Language: SMV – Specification Language: CTL – Presented by Jason Simas • Testing – Implementation Language: Java – Presented by Evren Sahin
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Dining Philosophers IPC Problem – Asynchronous processes & shared resources Philosophers are processes Resources are forks Solution: Modern Operating Systems pg. 127 – Freedom from starvation/deadlock – Exclusive use of resources – Maximal usage of resources
Background image of page 2
Solution : Philosopher #define N 5 /*number of philosophers*/ #define LEFT (i+N-1)%N /*i's left neighbour*/ #define RIGHT (i+1)%N /*i's right neighbour*/ #define THINKING 0 /*philosopher is thinking*/ #define HUNGRY 1 /*philosopher is trying to get the forks*/ #define EATING 2 /*philosopher is eating*/ typedef int semaphore; /*semaphores are special kind of integers*/ int state[N]; /*array to keep track of everyone's state*/ semaphore mutex; /*mutual exclusion for critical regions (init 1)*/ semaphore s[N] ; /*one semaphore per philosopher (init 0)*/ void philosopher(int i) { /*i:philosopher number, from 0 to N-1*/ while (TRUE) { /*repeat forever*/ think(); /*philosopher is thinking*/ take_forks(i); /*acquire two forks or block*/ eat(); /*yum-yum, spaghetti*/ put_forks(i); /*put both forks back on table*/ } }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Solution : Other void take_forks(int i) { /*i:philosopher number, from 0 to N-1*/ down(&mutex); /*enter critical region*/ state[i] = HUNGRY; /*record fact that philosopher is hungry*/ test(i); /*try to acquire 2 forks*/ up(&mutex); /*exit critical region*/ down(&s[i]); /*block if forks were not acquired*/ } void put_forks(int i) { /*i:philosopher number, from 0 to N-1*/ down(&mutex); /*enter critical region*/ state[i] = THINKING; /*philosopher has finished eating*/ test (LEFT)); /*see if left neighbour can now eat*/ test (RIGHT); /*see if right neighbour can now eat*/ up(&mutex); /*exit critical region*/ } void test (int i) { /*i:philosopher number, from 0 to N-1*/ if (state[i]==HUNGRY && state[LEFT]!=EATING && state[RIGHT]!=EATING) { state[i] = EATING; up(&s[i]); } }
Background image of page 4
SMV : Overview Abstraction Level: pseudo instructions (137 loc) Model checked for 5, 4, and 3 philosophers – Checked both even and odd number of philosophers. Checked whether: – Each philosopher gets to eat infinitely often No starvation, no deadlock – If a philosopher is eating, its neighbors are not eating Exclusive use of resources – Possibility for non-neighbors to eat simultaneously Maximal usage of resources
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
SMV : Model : Main : 5 MODULE main VAR ph_0 : process philosopher (0, n, mutex, sems, states); ph_1 : process philosopher (1, n, mutex, sems, states); ph_2 : process philosopher (2, n, mutex, sems, states); ph_3 : process philosopher (3, n, mutex, sems, states); ph_4 : process philosopher (4, n, mutex, sems, states); mutex : boolean; sems : array 0 .. 4 of boolean; states : array 0 .. 4 of {THINKING, HUNGRY, EATING};
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}