chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Question about mailbox egg


From: Timothy Beyer
Subject: [Chicken-users] Question about mailbox egg
Date: Sat, 21 Nov 2009 01:42:01 -0800
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.7 (Sanjō) APEL/10.6 MULE XEmacs/21.4 (patch 21) (Educational Television) (i386--freebsd)

Dear Chicken Users List,

I am writing a program that needs message passing, so I ran the example for the 
mailbox egg.

For some reason, when I run the following example code on the egg wiki page:

(require-extension mailbox)

(define (consumer ch)
  (make-thread
    (lambda ()
      (let loop () 
        (print (current-thread) ": reading " (mailbox-receive! ch))
        (loop) ) ) ) )

(define ch (make-mailbox))
(thread-start! (consumer ch))
(for-each
  (lambda (x)
    (print (current-thread) ": writing " x)
    (mailbox-send! ch x) )
  '(33 44 55 hello) )

I get the following output:

#<thread: primordial>: writing 33
#<thread: primordial>: writing 44
#<thread: primordial>: writing 55
#<thread: primordial>: writing hello

Instead of what I expected to see:

#<thread: primordial>: writing 33
#<thread: primordial>: reading 33
#<thread: primordial>: writing 44
#<thread: primordial>: reading 44 
#<thread: primordial>: writing 55
#<thread: primordial>: reading 55
#<thread: primordial>: writing hello
#<thread: primordial>: reading hello

Is the consumer thread just thunked such that it's code never excecutes?

Is there any easy way to get this behavior?

My apologies if I overlooked anything obvious.  I'm still using chicken 3.5.2, 
if that helps.

Regards,
Tim




reply via email to

[Prev in Thread] Current Thread [Next in Thread]