> On 06 22 19, at 6:14 AM, Robby Findler <ro...@cs.northwestern.edu> wrote:
> 
> One thing you can do, when the place-specific communication takes
> multiple steps is to, like you did in the first example, put the
> channels into a hash, but then on each iteration of the loop, pull all
> of them out and put them into a giant select that takes the relevant
> step forward for that specific piece of the communication

Not sure what you mean by "giant select" — ought that be "giant sync"? But as 
for "sequential access to some shared state" — In this toy example, maybe more 
along the lines of your suggestion, the server makes a random sequence of 
workers and triggers the workers in turn, so none of them are ever working at 
the same time. (So they could, in principle, all be writing to a single file.) 

I can imagine a more nuanced version involving each worker chekcing out sets of 
files, and the server permitting progress by more than one worker at a time, so 
long as the file sets didn't overlap.


#lang racket
(require racket/place racket/dict)
(provide main)

(define (main)
  (define server-p
    (place sch
           (define wp-dict (place-channel-get sch))
           (let loop ()
             (define wp-dict-shuffled (shuffle wp-dict))
             (displayln (format "order: ~a" (dict-keys wp-dict-shuffled)))
             (for ([(widx wp) (in-dict wp-dict-shuffled)])
               (displayln (format "server: start ~a" widx))
               (place-channel-put wp widx)
               (apply sync (dict-values wp-dict)))
             (loop))))
     
  (define worker-ps
    (for/list ([i (in-range (processor-count))])
      (place wch
             (let loop ()
               (define widx (place-channel-get wch))
               (sleep 0.2)
               (displayln (format "worker ~a: done" widx))
               (place-channel-put wch 'done)
               (loop)))))

  (place-channel-put server-p (for/list ([(wp widx) (in-indexed worker-ps)])
                                (cons widx wp)))
  
  (for-each place-wait worker-ps))

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/54475D15-78B1-4F3A-A06C-35739DFCBC57%40mbtype.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to