source: CIVL/examples/concurrency/diningBad.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 772 bytes
RevLine 
[72c01cc]1/* Dining philosophers, standard version, which deadlocks.
2 *
[9fb69d3]3 * civl verify -inputB=4 diningBad.cvl
4 * or (if you want to find the minimal counterexample)
5 * civl verify -inputB=4 diningBad.cvl -min
[72c01cc]6 */
[e6b02c8]7#include <civlc.cvh>
[72c01cc]8
[0baeebd]9$input int B = 4; // upper bound on number of philosophers
10$input int n; // number of philosophers
[3ff27cf]11$assume(2<=n && n<=B);
[72c01cc]12
[50786e0]13_Bool forks[n]; // Each fork will be on the table ($true) or in a hand ($false).
[72c01cc]14
15void dine(int id) {
16 int left = id;
17 int right = (id + 1) % n;
18
19 while (1) {
[50786e0]20 $when (forks[left]) forks[left] = $false;
21 $when (forks[right]) forks[right] = $false;
22 forks[right] = $true;
23 forks[left] = $true;
[72c01cc]24 }
25}
26
[7b9eb4c]27void main() {
28 $for(int i: 0 .. n-1)
[50786e0]29 forks[i] = $true;
[7b9eb4c]30 $parfor(int i: 0 .. n-1)
31 dine(i);
[72c01cc]32}
Note: See TracBrowser for help on using the repository browser.