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

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since cf2a996 was 9fb69d3, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

cleaned up examples/tests in concurrency folder.

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

  • Property mode set to 100644
File size: 917 bytes
Line 
1/* Dining philosophers, standard version, which deadlocks.
2 *
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
6 */
7#include <civlc.h>
8
9$input int B; // upper bound on number of philosophers
10$input int n; // number of philosophers
11$assume 2<=n && n<=B;
12
13// Each fork will be on the table (0) or in a hand (1).
14int forks[n];
15
16void dine(int id) {
17 int left = id;
18 int right = (id + 1) % n;
19
20 while (1) {
21 $when (forks[left] == 0) {forks[left] = 1;}
22 $when (forks[right] == 0) {forks[right] = 1;}
23 forks[right] = 0;
24 forks[left] = 0;
25 }
26}
27
28/* Put all forks on the table. */
29void init() {
30 for (int i = 0; i < n; i++) forks[i] = 0;
31}
32
33void main() {
34 $proc philosophers[n];
35
36 init();
37 for (int i = 0; i < n; i++)
38 philosophers[i] = $spawn dine(i);
39 for (int i = 0; i < n; i++)
40 $wait philosophers[i];
41}
Note: See TracBrowser for help on using the repository browser.