From 91c611e2afbef6491f16be2fca4bc42fe891b501 Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Wed, 5 Apr 2017 16:01:17 -0400 Subject: [PATCH] fixed an issue with username not appearing nicely --- concurrentreadandprint.rkt | 14 ++++++++++++-- 1 file 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))