Changes between Version 36 and Version 37 of Language
- Timestamp:
- 05/21/23 10:12:22 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Language
v36 v37 278 278 279 279 A 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 }}} 280 It spawns a new process and returns a reference to the new process, i.e., an object of [#proc-type type $proc]. 281 The syntax is the same as a function call with the keyword `$spawn` inserted in front: 282 `$spawn` ''function-expr'' `(` ( ''expr'' ( `,` expr )* )? `)` 283 Example: 284 {{{ 285 $spawn f(3.14, x+2*y) 286 }}} 287 285 288 Typically the returned value is assigned to a variable, e.g., 286 289 {{{ 287 290 $proc p = $spawn f(i); 288 291 }}} 289 If the function `f` returns a value, that value is simplyignored.292 If the function `f` returns a value, that value is ignored. 290 293 291 294 == Statements #statements … … 293 296 === Atomic blocks: `$atomic` #atomic 294 297 295 An ''atomic block'' is a statement of the form 298 An ''atomic block'' has syntax 299 `$atomic` `{` ( ''stmt'' ( `,` stmt )* )? `}` 300 For example, 296 301 {{{ 297 302 $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 }}} 307 It indicates that the statements comprising the block should be executed without the intervention of other processes. 304 308 305 309 More precisely, there is a global atomic lock which is initially free. … … 323 327 324 328 Atomic 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. 329 The semantics are as follows. 330 Each process maintains a counter which records the multiplicity with which it owns the atomic lock. 331 These counters are initially 0. 332 When 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. 335 When the counter reaches 0, the lock is released. 336 329 337 Execution of a `$yield` does not change the multiplicity; the process releases the lock but maintains the multiplicity, 330 338 so that when the lock is re-obtained, the original multiplicity is still in place.
