Changes between Version 39 and Version 40 of Language


Ignore:
Timestamp:
05/21/23 13:42:01 (3 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Language

    v39 v40  
    294294== Statements #statements
    295295
    296 === Atomic blocks: `$atomic` #atomic
    297 
    298 An ''atomic block'' has syntax
    299   `$atomic` `{` ( ''stmt'' ( `,` stmt )* )? `}`
     296=== Atomic statements: `$atomic` #atomic
     297
     298An atomic statement has syntax
     299  `$atomic` ''stmt''
     300It indicates that ''stmt'' should be executed without the intervention of other processes.
    300301For example,
    301302{{{
     
    305306}
    306307}}}
    307 It indicates that the statements comprising the block should be executed without the intervention of other processes.
    308 
    309 More precisely, there is a global atomic lock which is initially free.
    310 A process attempting to execute an atomic block will wait until the atomic lock becomes free, i.e., no other process is inside an atomic block.
    311 The process must also wait until the guard of the atomic block holds; this means that the first statement in the block is enabled.
    312 Once the atomic lock is free and the guard holds, the atomic block becomes enabled and the process may enter the atomic block.
    313 The process may not necessarily enter the atomic block as soon as these conditions hold, because some other enabled process may be scheduled first.
     308In this example, ''stmt'' is a compound statement `{` ... `}`.  This is usually the case.
     309
     310Semantics: there is a global atomic lock which is initially free.
     311A process attempting to execute an atomic statement will wait until the atomic lock becomes free, i.e., no other process is inside an atomic statement.
     312The process must also wait until the guard of the atomic statement holds; this means that the first sub-statement of the statement is enabled.
     313Once the atomic lock is free and the guard holds, the atomic statement becomes enabled and the process may enter the atomic statement.
     314The process may not necessarily enter the atomic statement as soon as these conditions hold, because some other enabled process may be scheduled first.
    314315In fact, some other process may obtain the atomic lock.
    315 But if the enabling conditions hold and this process is scheduled, it will obtain the atomic lock and begin executing the statements
    316 of the atomic block without other processes executing.
    317 Upon reaching the end of the atomic block, the process releases the atomic lock and exits the block.
    318 
    319 There is an exception to atomicity: if the process inside the atomic block executes a [#yield $yield statement], it releases the atomic lock.
     316But if the enabling conditions hold and this process is scheduled, it will obtain the atomic lock and begin executing ''stmt'' without other processes executing.
     317Upon reaching the end of ''stmt'', the process releases the atomic lock and exits ''stmt''.
     318
     319There is an exception to atomicity: if the process executing inside the atomic statement call the [#yield $yield function], it releases the atomic lock.
    320320This allows other processes to execute, and even obtain the lock.
    321321At any point at which the atomic lock is free and the first statement following the `$yield` is enabled, the original process may re-obtain
    322 the atomic lock and continue executing its block atomically.
    323 
    324 If a statement inside an atomic block blocks, so that the process executing the atomic block has no enabled statement, execution deadlocks.
    325 The exception to this rule is that the first statement in the atomic block, and the first statement after a `$yield`, as described above,
     322the atomic lock and continue executing atomically.
     323
     324If a statement inside an atomic statement blocks, so that the process executing the atomic statement has no enabled statement, execution deadlocks.
     325The exception to this rule is that the first sub-statement in the atomic statement, and the first statement after a `$yield`, as described above,
    326326may block, without necessarily causing deadlock.
    327327
     
    331331These counters are initially 0.
    332332When a process acquires the lock, the counter is set to 1.
    333 Each time the process attempts to enter an atomic block when it already owns the lock, it succeeds immediately and the counter is incremented.
    334 Each time the process leaves an atomic block, the counter is decremented.
     333Each time the process attempts to enter an atomic statement when it already owns the lock, it succeeds immediately and the counter is incremented.
     334Each time the process leaves an atomic statement, the counter is decremented.
    335335When the counter reaches 0, the lock is released.
    336336
    337 Execution of a `$yield` does not change the multiplicity; the process releases the lock but maintains the multiplicity,
     337Execution of a `$yield` does not change the multiplicity counter; the process releases the lock but maintains the multiplicity,
    338338so that when the lock is re-obtained, the original multiplicity is still in place.
    339339