On Sat, 12 Aug 2017 16:17:21 -0700 (PDT), Zelphir Kaltstahl <zelphirkaltst...@gmail.com> wrote:
>Is it in general not possible to use a place more than once? No problem. A very simple example is shown below. This example only demonstrates that places can remain running and responding to new requests. Real interaction between the coordinator [main program] and the places [threads] is left as an exercise. George ################################################## #lang racket ;================================== (define place-body (let [ (output (? (fmt . whatever) (apply eprintf fmt whatever) (flush-output (current-error-port)) )) (id #f) ] (lambda (ch) (output "place starting~n") (let/ec done (let loop [ (msg (place-channel-get ch)) ] (match msg ([list 'init val] (set! id val) ) ('terminate (done) ) (else (output "place ~s: ~s~n" id msg) )) (loop (place-channel-get ch)) )) (output "place ~s stopping~n" id) ))) ;================================== (define my-places (list)) (define (start-places how-many) (for/list [(i how-many)] (let [ (p #f) (_i #f)(_o #f)(_e #f) ] (set!-values (p _i _o _e) (place* #:err (current-error-port) ch (place-body ch))) (printf "created place ~s~n" i) (place-channel-put p (list 'init i )) p ))) (define (stop-places lst) (for [(p lst)] (place-channel-put p 'terminate) (place-wait p) )) ;================================== (define (main) (set! my-places (start-places 3)) (sleep 1) (let loop [ (msg (list 'the 'quick 'brown 'fox 'jumped 'over 'the 'lazy 'dogs)) (index 0) ] (cond ([null? msg]) (else (place-channel-put (list-ref my-places index) (car msg)) (loop (cdr msg) (remainder (+ index 1) (length my-places))) )) ) (sleep 1) (stop-places my-places) ) ################################################## -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.