aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-05 15:46:50 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-05 15:46:50 -0400
commit768395102489dab0997ca6b7180c28e51872e665 (patch)
treee2056b969fb70b77986bf7a055727930e086cbe3
parenta93d17e0e65458e8dbadf5d510229b0a9c9e1470 (diff)
properly kills threads and returns prompt to main
-rw-r--r--concurrentreadandprint.rkt9
1 files changed, 8 insertions, 1 deletions
diff --git a/concurrentreadandprint.rkt b/concurrentreadandprint.rkt
index 2272d97..a9a71ed 100644
--- a/concurrentreadandprint.rkt
+++ b/concurrentreadandprint.rkt
@@ -2,6 +2,10 @@
;; author: Ibrahim Mkusa
;; 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
(define (read-loop)
(display (read-line))
@@ -25,7 +29,8 @@
(semaphore-wait fair)
(define input (read-line))
;; 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"))
(semaphore-post fair)
(read-loop-i)
@@ -43,6 +48,8 @@
(read-loop-i))))
(define a (thread (lambda ()
(hello-world))))
+
+(thread-wait t) ;; returns prompt back to drracket
;; below doesn't execute
; (sleep 10)
; (kill-thread t)