Changes between Version 7 and Version 8 of Introduction


Ignore:
Timestamp:
12/28/18 20:39:21 (7 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Introduction

    v7 v8  
    5252=== Verifying CIVL-C Programs ===
    5353
     54Dining philosophers:
     55
     56{{{
     57$input int B = 4; // upper bound on number of philosophers
     58$input int n;     // number of philosophers
     59$assume(2<=n && n<=B);
     60
     61_Bool forks[n]; // Each fork will be on the table ($true) or in a hand ($false).
     62
     63void dine(int id) {
     64  int left = id;
     65  int right = (id + 1) % n;
     66  while (1) {
     67    $when (forks[left]) forks[left] = $false;
     68    $when (forks[right]) forks[right] = $false;
     69    forks[right] = $true;
     70    forks[left] = $true;
     71  }
     72}
     73
     74void main() {
     75  $for(int i: 0..n-1) forks[i] = $true;
     76  $parfor(int i: 0..n-1) dine(i);
     77}
     78}}}
     79
    5480
    5581=== Verifying C Programs ===