source: CIVL/examples/concurrency/diningBad.cvl@ 50f834b

1.23 2.0 main test-branch
Last change on this file since 50f834b was 48bfab9, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added checking for memory leak when collecting a dyscope and for process leak when the main process returns; fixed all test cases accordingly; added a filesystem_destroy call for IOTransformer to get rid of memory leak.

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

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