chickadee » srfi-216 » parallel-execute

parallel-execute p1 p2 ...procedure

Each argument must be a procedure of no arguments. parallel-execute creates a separate process for each argument, and that process applies the argument to no arguments. These processes all run concurrently.

See SICP Section 3.4.2, Subsection "Serializers in Scheme".

Example:

(import (srfi 216))
(define x 10)
(parallel-execute
  (lambda () (set! x (* x x))) ; P1
  (lambda () (set! x (+ x 1)))) ; P2
;; May assign to x any of the following:
;; 101 - P1 sets x to 100 and then P2 increments x to 101.
;; 121 - P2 increments x to 11 and then P1 sets x to x * x.
;; 110 - P2 changes x from 10 to 11 between the two times that P1 accesses the value of x during the evaluation of (* x x).
;; 11 - P2 accesses x, then P1 sets x to 100, then P2 sets x.
;; 100 - P1 accesses x (twice), then P2 sets x to 11, then P 1 sets x.