source:
CIVL/examples/concurrency/diningBad.cvl
| Last change on this file was ea777aa, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 772 bytes | |
| Rev | Line | |
|---|---|---|
| [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 | |
| 15 | void 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] | 27 | void 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.
