[gambit-list] How thread-mailbox-extract-without-rewind

Adrien Piérard pierarda at iro.umontreal.ca
Mon Oct 31 07:27:38 EDT 2011


What about using queues as proxy for your mailbox?
Basically and naively:

(let loop ()
 (read-a)
 (read-b)
 (read-c)))

and

(define (read-a)
 (let ((msg (dequeue! queue-a #f)))
  (if msg
   msg
   (let ((msg (thread-receive)))
     (cond
      ((is-a? msg) msg)
      ((is-b? msg) (enqueue! queue-b msg) (read-a))
      ((is-c? msg) (enqueue! queue-c msg) (read-a)))))))

The two others are similar.
Doing this, you keep the order you wanted, and it doesn't take much
more memory: in the worse case, you just dispatch your whole mailbox
into three queues, preserving the order in each of them.

Doesn't this solve your problem?


P!

-- 
Français, English, 日本語, 한국어



More information about the Gambit-list mailing list