Odd mailbox behaviour pasted by sjw on Mon Aug 27 22:27:50 2012
(use mailbox srfi-18) (use miscmacros thread-utils) (define (log-mailbox mbx) (printf "((current-thread: ~S) (mailbox-waiting? ~S) (mailbox-waiting? ~S) (mailbox-count ~S))~N" (thread-name (current-thread)) (mailbox-waiting? mbx) (mailbox-waiters mbx) (mailbox-count mbx))) (let* ((my-box (make-mailbox)) (proc (lambda () (fprintf (current-error-port) "Hello from ~S!~N" (current-thread)) (fprintf (current-error-port) "Message ~S was received by ~S~N" (mailbox-receive! my-box) (current-thread)) (log-mailbox my-box))) (thread (thread-start! (make-thread proc)))) ; Ensure thread is running. (while (thread-ready? thread) (pp (thread-state thread)) (thread-yield!)) (log-mailbox my-box) ; Check to see if thread is actually watching the mailbox. (if (mailbox-waiting? my-box) (begin (mailbox-send! my-box "any data") (log-mailbox my-box) (while (mailbox-waiting? my-box) (thread-yield!)) (log-mailbox my-box))) ; Now listen for messages ourselves (proc))
mailboxes added by megane on Mon Aug 27 22:54:41 2012
(use mailbox srfi-18) (use miscmacros thread-utils) (define (log-mailbox mbx) (printf "((current-thread: ~S) (mailbox-waiting? ~S) (mailbox-waiting? ~S) (mailbox-count ~S))~N" (thread-name (current-thread)) (mailbox-waiting? mbx) (mailbox-waiters mbx) (mailbox-count mbx))) (let* ((my-box (make-mailbox)) (proc (lambda () (fprintf (current-error-port) "Hello from ~S!~N" (current-thread)) (fprintf (current-error-port) "Message ~S was received by ~S~N" (mailbox-receive! my-box) (current-thread)) (log-mailbox my-box))) (thread (thread-start! (make-thread proc)))) ; Ensure thread is running. (while (thread-ready? thread) (print "state" thread) (pp (thread-state thread)) (thread-yield!)) (log-mailbox my-box) ; Check to see if thread is actually watching the mailbox. (if (mailbox-waiting? my-box) (begin (mailbox-send! my-box "any data") (log-mailbox my-box) (while (mailbox-waiting? my-box) (thread-yield!)) (log-mailbox my-box))) ; Now listen for messages ourselves (proc) (use posix) (let lp [] (log-mailbox my-box) (thread-yield!) (sleep 1) (lp)) ) state#<thread: thread93> ready Hello from #<thread: thread93>! ((current-thread: primordial) (mailbox-waiting? #t) (mailbox-waiting? (#<thread: thread93>)) (mailbox-count 0)) ((current-thread: primordial) (mailbox-waiting? #f) (mailbox-waiting? ()) (mailbox-count 1)) ((current-thread: primordial) (mailbox-waiting? #f) (mailbox-waiting? ()) (mailbox-count 1)) Hello from #<thread: primordial>! Message "any data" was received by #<thread: primordial> ((current-thread: primordial) (mailbox-waiting? #f) (mailbox-waiting? ()) (mailbox-count 0)) ; loading library posix ... ((current-thread: primordial) (mailbox-waiting? #f) (mailbox-waiting? ()) (mailbox-count 0)) ((current-thread: primordial) (mailbox-waiting? #t) (mailbox-waiting? (#<thread: thread93>)) (mailbox-count 0)) ((current-thread: primordial) (mailbox-waiting? #t) (mailbox-waiting? (#<thread: thread93>)) (mailbox-count 0)) ((current-thread: primordial) (mailbox-waiting? #t) (mailbox-waiting? (#<thread: thread93>)) (mailbox-count 0))