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
|
| 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.cvh>
|
|---|
| 8 |
|
|---|
| 9 | $input int B = 4; // upper bound on number of philosophers
|
|---|
| 10 | $input int n; // number of philosophers
|
|---|
| 11 | $assume(2<=n && n<=B);
|
|---|
| 12 |
|
|---|
| 13 | _Bool forks[n]; // Each fork will be on the table ($true) or in a hand ($false).
|
|---|
| 14 |
|
|---|
| 15 | void dine(int id) {
|
|---|
| 16 | int left = id;
|
|---|
| 17 | int right = (id + 1) % n;
|
|---|
| 18 |
|
|---|
| 19 | while (1) {
|
|---|
| 20 | $when (forks[left]) forks[left] = $false;
|
|---|
| 21 | $when (forks[right]) forks[right] = $false;
|
|---|
| 22 | forks[right] = $true;
|
|---|
| 23 | forks[left] = $true;
|
|---|
| 24 | }
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | void main() {
|
|---|
| 28 | $for(int i: 0 .. n-1)
|
|---|
| 29 | forks[i] = $true;
|
|---|
| 30 | $parfor(int i: 0 .. n-1)
|
|---|
| 31 | dine(i);
|
|---|
| 32 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.