Changes between Version 6 and Version 7 of Language


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

--

Legend:

Unmodified
Added
Removed
Modified
  • Language

    v6 v7  
    363363=== Guarded commands: `$when`
    364364
     365A guarded command is encoded in CIVL-C using a `$when` statement:
     366{{{
     367$when (expr) stmt;
     368}}}
     369All statements have a guard, either implicit or explicit. For most statements, the guard is ''true''. The `$when` statement allows one to attach an explicit guard to a statement.
     370
     371When `expr` is ''true'', the statement is enabled, otherwise it is disabled.
     372A disabled statement is blocked—it will not be scheduled for execution.
     373When it is enabled, it may execute by moving control to the `stmt` and executing the first atomic action in the `stmt`.
     374If `stmt` itself has a non-trivial guard, the guard of the `$when` statement is the conjunction of the `expr` and the guard of `stmt`.
     375
     376The evaluation of `expr` and the first atomic action of `stmt` occur as a single atomic action.
     377There is no guarantee that execution of `stmt` will continue atomically if it contains more than one atomic action, i.e., other processes may be scheduled.
     378
     379Examples:
     380
     381{{{
     382$when (s>0) s--;
     383}}}
     384This will block until `s` is positive and then decrement `s`.
     385The execution of `s--` is guaranteed to take place in an environment in which `s` is positive.
     386
     387{{{
     388$when (s>0) { s--; t++; }
     389}}}
     390The execution of `s--` must happen when `s>0`, but between `s--` and `t++`, other processes may execute.
     391
     392{{{
     393$when (s>0) $when (t>0) x=y*t;
     394}}}
     395This blocks until both `x` and `t` are positive then executes the assignment in that state.
     396It is equivalent to
     397{{{
     398$when (s>0 && t>0) x=y*t;
     399}}}
     400
     401
     402The following statements are all equivalent:
     403{{{
     404$when (s>0) $atomic{ s--; t++; }
     405$atomic{ $when(s>0); s--; t++; }
     406$atomic{ $when(s>0) {s--; t++; } }
     407}}}
     408Each of these waits until `s` is positive, then from such a state, decrements `s` and increments `t` without the intervention of other processes.
    365409
    366410== Functions