Changes between Version 36 and Version 37 of Language


Ignore:
Timestamp:
05/21/23 10:12:22 (3 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Language

    v36 v37  
    278278
    279279A spawn expression is an expression with side-effects.
    280 It spawns a new process and returns a reference to the new process, i.e., an object of type $proc.
    281 The syntax is the same as a procedure invocation with the keyword `$spawn` inserted in front:
    282 {{{
    283 $spawn f(expr1, ..., exprn)
    284 }}}
     280It spawns a new process and returns a reference to the new process, i.e., an object of [#proc-type type $proc].
     281The syntax is the same as a function call with the keyword `$spawn` inserted in front:
     282  `$spawn` ''function-expr'' `(` ( ''expr'' ( `,` expr )* )? `)`
     283Example:
     284{{{
     285$spawn f(3.14, x+2*y)
     286}}}
     287
    285288Typically the returned value is assigned to a variable, e.g.,
    286289{{{
    287290$proc p = $spawn f(i);
    288291}}}
    289 If the function `f` returns a value, that value is simply ignored.
     292If the function `f` returns a value, that value is ignored.
    290293
    291294== Statements #statements
     
    293296=== Atomic blocks: `$atomic` #atomic
    294297
    295 An ''atomic block'' is a statement of the form
     298An ''atomic block'' has syntax
     299  `$atomic` `{` ( ''stmt'' ( `,` stmt )* )? `}`
     300For example,
    296301{{{
    297302$atomic {
    298   stmt1;
    299   stmt2;
    300   ...
    301 }
    302 }}}
    303 and indicates that the statements comprising the block should be executed without the intervention of other processes.
     303  x=x+1;
     304  y=2*x+y;
     305}
     306}}}
     307It indicates that the statements comprising the block should be executed without the intervention of other processes.
    304308
    305309More precisely, there is a global atomic lock which is initially free.
     
    323327
    324328Atomic blocks may be nested.
    325 Hence the atomic lock is held with a certain multiplicity.
    326 Each time the process enters an atomic block, the multiplicity is incremented.
    327 Each time it leaves an atomic block, the multiplicity is decremented.
    328 When the multiplicity hits 0, the atomic lock is released.
     329The semantics are as follows.
     330Each process maintains a counter which records the multiplicity with which it owns the atomic lock.
     331These counters are initially 0.
     332When a process acquires the lock, the counter is set to 1.
     333Each time the process attempts to enter an atomic block when it already owns the lock, it succeeds immediately and the counter is incremented.
     334Each time the process leaves an atomic block, the counter is decremented.
     335When the counter reaches 0, the lock is released.
     336
    329337Execution of a `$yield` does not change the multiplicity; the process releases the lock but maintains the multiplicity,
    330338so that when the lock is re-obtained, the original multiplicity is still in place.