properly kills threads and returns prompt to main

This commit is contained in:
Ibrahim Mkusa 2017-04-05 15:46:50 -04:00
parent a93d17e0e6
commit 7683951024

View File

@ -2,6 +2,10 @@
;; author: Ibrahim Mkusa ;; author: Ibrahim Mkusa
;; about: print and read concurrently ;; about: print and read concurrently
;; create custodian for managing all resources
;; so we can shutdown everything at once
(define guard (make-custodian (current-custodian)))
(current-custodian guard)
;; reads values continously from stdin and redisplays them ;; reads values continously from stdin and redisplays them
(define (read-loop) (define (read-loop)
(display (read-line)) (display (read-line))
@ -25,7 +29,8 @@
(semaphore-wait fair) (semaphore-wait fair)
(define input (read-line)) (define input (read-line))
;; do something over here with input maybe send it out ;; do something over here with input maybe send it out
(cond ((string=? input "quit") (exit))) (cond ((string=? input "quit") (begin (kill-thread a)
(kill-thread t))))
(display (string-append output-prompt input "\n")) (display (string-append output-prompt input "\n"))
(semaphore-post fair) (semaphore-post fair)
(read-loop-i) (read-loop-i)
@ -43,6 +48,8 @@
(read-loop-i)))) (read-loop-i))))
(define a (thread (lambda () (define a (thread (lambda ()
(hello-world)))) (hello-world))))
(thread-wait t) ;; returns prompt back to drracket
;; below doesn't execute ;; below doesn't execute
; (sleep 10) ; (sleep 10)
; (kill-thread t) ; (kill-thread t)