首页

2010年5月29日星期六

Scheme/Lisp 启动一个进程中启动多线程!

(define thd-a (thread (lambda ()
      (let loop ((m (thread-receive)))
         (cond
            ((equal? m 'hello!)
              (thread-send thd-b 'nihao!))
            ((equal? m 'bye-bye!)
              (kill-thread thd-a))
            (else
              (loop (thread-receive))))))))

(define thd-b (thread (lambda ()
      (let loop ((n(thread-receive)))
         (cond
            ((equal? n 'nihao!)
              (thread-send thd-a 'hello!))
            ((equal? n 'bye-bye)
              (kill-thread thd-b))
            (else
               (loop (thread-receive))))))))

没有评论:

发表评论