concurrency - ;; Implementation of parallel-execute using...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ;; Implementation of parallel-execute using call/cc. ;; ;; By Ben Rudiak-Gould, 10/2002. ;; ;; Requires STk (for "procedure-body" and first-class environments). (define call/cc call-with-current-continuation) (define (parallel-execute . thunks) (apply run-concurrently-with-env random (map (lambda (thunk) (cons (list (uncode (procedure-body thunk))) (make-virtual-env (procedure-environment thunk)) )) thunks )) 'okay ) (define (run-concurrently select . exprs) (apply run-concurrently-with-env select (map (lambda (x) (cons x (make-virtual-env (global-environment))) ) exprs ))) (define (run-concurrently-with-env select . exprs-with-envs) (let ((threads (map (lambda (exp-env) (list (call/cc (lambda (cont) (let ((scheduler (call/cc cont))) (scheduler (myeval (car exp-env) (cdr exp-env) scheduler ))))))) exprs-with-envs ))) (let loop () (let ((active-threads (filter (lambda (x) (continuation? (car x))) threads) )) (if (null? active-threads) (map car threads) (let ((active (list-ref active-threads (select (length active-threads)) ))) (set-car! active (call/cc (car active))) (loop) )))))) (define (make-virtual-env real-env) (cons `((quote **macro** ,macro-quote) (lambda **macro** ,macro-lambda) (let **macro** ,macro-let) (set! **macro** ,macro-set!) (define **macro** ,macro-define) (if **macro** ,macro-if) (cond **macro** ,macro-cond) (and **macro** ,macro-and) (or **macro** ,macro-or) (set-car! **prim** (set-car!...
View Full Document

This note was uploaded on 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at University of California, Berkeley.

Page1 / 5

concurrency - ;; Implementation of parallel-execute using...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online