1.23
2.0
main
test-branch
|
Last change
on this file since 4f22a92 was 72c01cc, checked in by Stephen Siegel <siegel@…>, 13 years ago |
|
Continuing to clean up examples, but just realized the minimal
depth search is not quite right, it won't necessarily find
the minimum, as revealed by dining philosophers.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@268 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
819 bytes
|
| Rev | Line | |
|---|
| [72c01cc] | 1 | /* Dining philosophers, standard version, which deadlocks.
|
|---|
| 2 | *
|
|---|
| 3 | * civl verify -inputB=4 dining.cvl
|
|---|
| 4 | */
|
|---|
| 5 | #include <civlc.h>
|
|---|
| 6 |
|
|---|
| 7 | $input int B; // upper bound on number of philosophers
|
|---|
| 8 | $input int n; // number of philosophers
|
|---|
| 9 | $assume 2<=n && n<=B;
|
|---|
| 10 |
|
|---|
| 11 | // Each fork will be on the table (0) or in a hand (1).
|
|---|
| 12 | int forks[n];
|
|---|
| 13 |
|
|---|
| 14 | void dine(int id) {
|
|---|
| 15 | int left = id;
|
|---|
| 16 | int right = (id + 1) % n;
|
|---|
| 17 |
|
|---|
| 18 | while (1) {
|
|---|
| 19 | $when (forks[left] == 0) {forks[left] = 1;}
|
|---|
| 20 | $when (forks[right] == 0) {forks[right] = 1;}
|
|---|
| 21 | forks[right] = 0;
|
|---|
| 22 | forks[left] = 0;
|
|---|
| 23 | }
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | /* Put all forks on the table. */
|
|---|
| 27 | void init() {
|
|---|
| 28 | for (int i = 0; i < n; i++) forks[i] = 0;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | void main() {
|
|---|
| 32 | $proc philosophers[n];
|
|---|
| 33 |
|
|---|
| 34 | init();
|
|---|
| 35 | for (int i = 0; i < n; i++)
|
|---|
| 36 | philosophers[i] = $spawn dine(i);
|
|---|
| 37 | for (int i = 0; i < n; i++)
|
|---|
| 38 | $wait philosophers[i];
|
|---|
| 39 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.