ytakenaka #6364(2008/05/28 06:42 GMT) [ Common Lisp ] Rating0/0=0.00
sbcl依存のthreadパッケージを利用しています。一つわからない ことがあって、それはdefpackage - in-packageの流れでパッケー ジ化すると、うまく動かないところです。 thread programmingははじめてなので、変数の取り扱いの 注意点が抜けてるみたいです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
(defun print-a () (format *standard-output* "a") (finish-output) (sleep 1)) (defmacro read-thread(res) `(sb-thread:make-thread (lambda()(setf ,res (read *standard-input*))))) (defun main () (let* ((res nil) (stop nil) (thread (read-thread res))) (loop do (if (null (sb-thread:thread-alive-p thread)) (case res ((q) (return)) ((p) (and stop (print-a)) (setf stop (not stop) thread (read-thread res))) (otherwise (unless stop (print-a)) (setf thread (read-thread res)))) (unless stop (print-a))))))
Rating0/0=0.00-0+
1 reply [ reply ]
ytakenaka
#6364()
[
Common Lisp
]
Rating0/0=0.00
(defun print-a () (format *standard-output* "a") (finish-output) (sleep 1)) (defmacro read-thread(res) `(sb-thread:make-thread (lambda()(setf ,res (read *standard-input*))))) (defun main () (let* ((res nil) (stop nil) (thread (read-thread res))) (loop do (if (null (sb-thread:thread-alive-p thread)) (case res ((q) (return)) ((p) (and stop (print-a)) (setf stop (not stop) thread (read-thread res))) (otherwise (unless stop (print-a)) (setf thread (read-thread res)))) (unless stop (print-a))))))Rating0/0=0.00-0+
1 reply [ reply ]