Created
December 14, 2014 14:58
-
-
Save y-taka-23/75d013bef09faeb77203 to your computer and use it in GitHub Desktop.
An Invalid (Deadlocked) Model of Resource Sharing Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Resource Sharing Problem (Example for Deadlock) | |
*/ | |
mtype = { LOCK, UNLOCK }; | |
proctype Client(chan to_res1, to_res2) { | |
if | |
:: to_res1 ! LOCK(_pid); | |
to_res2 ! LOCK(_pid); | |
:: to_res2 ! LOCK(_pid); | |
to_res1 ! LOCK(_pid); | |
fi; | |
if | |
:: to_res1 ! UNLOCK(_pid); | |
to_res2 ! UNLOCK(_pid); | |
:: to_res2 ! UNLOCK(_pid); | |
to_res1 ! UNLOCK(_pid); | |
fi | |
} | |
proctype Resource(chan to_res) { | |
pid locker; | |
pid unlocker; | |
end: | |
do | |
:: to_res ? LOCK(locker); | |
to_res ? UNLOCK(unlocker); | |
assert(locker == unlocker); | |
od | |
} | |
init { | |
chan to_scanner = [0] of { mtype, pid }; | |
chan to_printer = [0] of { mtype, pid }; | |
atomic { | |
run Client(to_scanner, to_printer); | |
run Client(to_scanner, to_printer); | |
run Resource(to_scanner); | |
run Resource(to_printer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment