(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))))))