main
test-branch
| Line | |
|---|
| 1 | $input int B = 4; // upper bound on number of philosophers
|
|---|
| 2 | $input int n; // number of philosophers
|
|---|
| 3 | $assume(2<=n && n<=B);
|
|---|
| 4 |
|
|---|
| 5 | _Bool forks[n]; // Each fork will be on the table ($true) or in a hand ($false).
|
|---|
| 6 |
|
|---|
| 7 | void dine(int id) {
|
|---|
| 8 | int left = id;
|
|---|
| 9 | int right = (id + 1) % n;
|
|---|
| 10 | while (1) {
|
|---|
| 11 | $when (forks[left]) forks[left] = $false;
|
|---|
| 12 | $when (forks[right]) forks[right] = $false;
|
|---|
| 13 | forks[right] = $true;
|
|---|
| 14 | forks[left] = $true;
|
|---|
| 15 | }
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | void main() {
|
|---|
| 19 | $for(int i: 0..n-1) forks[i] = $true;
|
|---|
| 20 | $parfor(int i: 0..n-1) dine(i);
|
|---|
| 21 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.