Changes between Version 24 and Version 25 of Language


Ignore:
Timestamp:
05/19/23 17:59:43 (3 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Language

    v24 v25  
    571571in the sense that it is not necessary to explore all interleavings from the state where the local is enabled.
    572572
     573==== Example
     574
     575The following illustrates the difference between local and atomic regions.
     576{{{
     577int x = 0;
     578void thread(int tid) {
     579  $atomic {
     580    x = tid;
     581  }
     582}
     583int main() {
     584  $parfor (int i:1..2) thread(i);
     585  $assert(x==2); // violated
     586}
     587}}}
     588The program above spawns two threads, each of which writes to shared variable `x` in an atomic block.
     589The program has two possible executions: in one, thread 1 writes first, then thread 2 writes; in the other, thread 2 writes first, then thread 1 writes.
     590The assertion is violated on the second execution.
     591Running `civl verify` on this code will report a violation.
     592
     593{{{
     594int x = 0;
     595void thread(int tid) {
     596  $local_start();
     597  x = tid;
     598  $local_end();
     599}
     600int main() {
     601  $parfor (int i:1..2) thread(i);
     602  $assert(x==2); // valid
     603}
     604}}}
     605In this program, the threads write to `x` within a local region.  This program has only one execution: first thread 1 executes the complete local region, then thread 2 executes the complete local region.  Running `civl verify` on this code yields "all properties hold".
     606
     607==== Use of `$yield` within a local region
     608
    573609Local blocks can also be broken up at specified points using function `$yield`.
    574610If ''t'' owns the atomic lock and calls `$yield`, then ''t'' relinquishes the lock and does not immediately return from the call.