aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-05 16:01:17 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-05 16:01:17 -0400
commit91c611e2afbef6491f16be2fca4bc42fe891b501 (patch)
treec131a7045e0eae5bad36068a39fee0c34c72e3b9
parent768395102489dab0997ca6b7180c28e51872e665 (diff)
fixed an issue with username not appearing nicely
-rw-r--r--concurrentreadandprint.rkt14
1 files changed, 12 insertions, 2 deletions
diff --git a/concurrentreadandprint.rkt b/concurrentreadandprint.rkt
index a9a71ed..7e7a78b 100644
--- a/concurrentreadandprint.rkt
+++ b/concurrentreadandprint.rkt
@@ -1,4 +1,6 @@
#lang racket
+(require math/base) ;; for random number generation
+
;; author: Ibrahim Mkusa
;; about: print and read concurrently
@@ -24,11 +26,15 @@
;; intelligent read, quits when user types in "quit"
(define (read-loop-i)
- (display usernamei)
+
(semaphore-wait fair)
+ (display usernamei)
(define input (read-line))
;; do something over here with input maybe send it out
+
+ ;; Tests input if its a quit then kills all threads
+ ;; An if would be better here tbh
(cond ((string=? input "quit") (begin (kill-thread a)
(kill-thread t))))
(display (string-append output-prompt input "\n"))
@@ -38,9 +44,13 @@
;; print hello world continously
+;; "(hello-world)" can be executed as part of background thread
+;; that prints in the event there is something in the input port
(define (hello-world)
+ (sleep (random-integer 0 60)) ;; sleep between 0 and 60 seconds to simulate coms
+ ;; with server
(semaphore-wait fair)
- (display "Hello, World!\n")
+ (display "\nHello, World!\n")
(semaphore-post fair)
(hello-world))