source: CIVL/examples/concurrency/diningBad.cvl@ c1012e4

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since c1012e4 was 7b9eb4c, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

fixed model builder to allow range expression in $for/$parfor, e.g.: $parfor(int i: 0 .. N-1) process(i);

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

  • Property mode set to 100644
File size: 765 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
[4e1d3c7]13int forks[n]; // Each fork will be on the table (0) or in a hand (1).
[72c01cc]14
15void dine(int id) {
16 int left = id;
17 int right = (id + 1) % n;
18
19 while (1) {
[4e1d3c7]20 $when (forks[left] == 0) forks[left] = 1;
21 $when (forks[right] == 0) forks[right] = 1;
[72c01cc]22 forks[right] = 0;
23 forks[left] = 0;
24 }
25}
26
[7b9eb4c]27void main() {
28 elaborate(n);
29 $for(int i: 0 .. n-1)
30 forks[i] = 0;
31 $parfor(int i: 0 .. n-1)
32 dine(i);
[72c01cc]33}
Note: See TracBrowser for help on using the repository browser.