diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-01-25 11:38:13 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-01-25 11:38:13 -0800 |
commit | d1f57fa1ab95a36a562d2b75a064bc387bd2d5d3 (patch) | |
tree | 6ca27a8e3ea7a555811241ee6cf8229966997a3f | |
parent | 4ca73eb66a57f32085be56c64ce316b82084602f (diff) | |
download | mu-d1f57fa1ab95a36a562d2b75a064bc387bd2d5d3.tar.gz |
621 - fix race condition in buffered-stdin.mu
-rw-r--r-- | buffered-stdin.mu | 6 | ||||
-rw-r--r-- | mu.arc | 37 |
2 files changed, 24 insertions, 19 deletions
diff --git a/buffered-stdin.mu b/buffered-stdin.mu index a0e39154..3f4030b9 100644 --- a/buffered-stdin.mu +++ b/buffered-stdin.mu @@ -2,8 +2,8 @@ ; dies if you wait a while, because so far we never free memory (function main [ (default-space:space-address <- new space:literal 30:literal) - (cursor-mode) - (clear-screen) + (cursor-mode) ;? 1 + (clear-screen) ;? 1 ; hook up stdin (stdin:channel-address <- init-channel 1:literal) (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit nil:literal/keyboard stdin:channel-address) @@ -15,7 +15,7 @@ (s:string-address <- new "? ") (print-string nil:literal/terminal s:string-address) { begin - (x:tagged-value stdin:channel-address/deref <- read buffered-stdin:channel-address) + (x:tagged-value buffered-stdin:channel-address/deref <- read buffered-stdin:channel-address) (c:character <- maybe-coerce x:tagged-value character:literal) ;? (print-primitive-to-host (("AAA " literal))) ;? 1 ;? (print-primitive-to-host c:character) ;? 1 diff --git a/mu.arc b/mu.arc index 1f9c1062..b06d402f 100644 --- a/mu.arc +++ b/mu.arc @@ -475,7 +475,7 @@ (die "No results returned: @(tostring:pr (body.routine* pc.routine*))")) (++ pc.routine*)) (++ curr-cycle*) -;? (trace "run" "-- " int-canon.memory*) +;? (trace "run" "-- " int-canon.memory*) ;? 1 (trace "run" curr-cycle* " " top.routine*!fn-name " " pc.routine* ": " (body.routine* pc.routine*)) ;? (trace "run" routine*) (when (atom (body.routine* pc.routine*)) ; label @@ -751,7 +751,7 @@ (wipe dump-trace*)) $dump-channel (do1 nil - ($.close-charterm) + ($.close-charterm) ;? 1 (withs (x (m arg.0) y (memory* (+ x 2))) (prn label.routine* " -- " x " -- " (list (memory* x) @@ -762,7 +762,8 @@ (repr:memory* (+ y 2)) (memory* (+ y 3)) (repr:memory* (+ y 4))))) - ($.open-charterm)) + ($.open-charterm) ;? 1 + ) $quit (quit) @@ -1702,7 +1703,7 @@ (init-fn read (default-space:space-address <- new space:literal 30:literal) (chan:channel-address <- next-input) -;? ($dump-channel chan:channel-address) ;? 1 +;? ($dump-channel chan:channel-address) ;? 2 { begin ; block if chan is empty (empty:boolean <- empty? chan:channel-address/deref) @@ -2035,15 +2036,21 @@ (default-space:space-address <- new space:literal 30:literal) (k:keyboard-address <- next-input) (stdin:channel-address <- next-input) - { begin - (c:character <- read-key k:keyboard-address) - (loop-unless c:character) - (curr:tagged-value <- save-type c:character) - (stdin:channel-address/deref <- write stdin:channel-address curr:tagged-value) - (eof?:boolean <- equal c:character ((#\null literal))) - (break-if eof?:boolean) - (loop) - } +;? (c:character <- copy ((#\a literal))) ;? 1 +;? (curr:tagged-value <- save-type c:character) ;? 1 +;? (stdin:channel-address/deref <- write stdin:channel-address curr:tagged-value) ;? 1 +;? (c:character <- copy ((#\newline literal))) ;? 1 +;? (curr:tagged-value <- save-type c:character) ;? 1 +;? (stdin:channel-address/deref <- write stdin:channel-address curr:tagged-value) ;? 1 + { begin ;? 1 + (c:character <- read-key k:keyboard-address) ;? 1 + (loop-unless c:character) ;? 1 + (curr:tagged-value <- save-type c:character) ;? 1 + (stdin:channel-address/deref <- write stdin:channel-address curr:tagged-value) ;? 1 + (eof?:boolean <- equal c:character ((#\null literal))) ;? 1 + (break-if eof?:boolean) ;? 1 + (loop) ;? 1 + } ;? 1 ) (init-fn buffer-stdin @@ -2053,8 +2060,6 @@ ; repeat forever { begin (line:buffer-address <- init-buffer 30:literal) - ; todo: why do we need this? - (sleep for-some-cycles:literal 1:literal) ;? ($dump-channel 1093:literal) ;? 1 ; read characters from stdin until newline, copy into line { begin @@ -2386,7 +2391,7 @@ ;? (= dump-trace* (obj whitelist '("run"))) ;? (= dump-trace* (obj whitelist '("schedule"))) ;? (= dump-trace* (obj whitelist '("cn0" "cn1"))) -;? (set dump-trace*) ;? 0 +;? (set dump-trace*) ;? 1 ;? (freeze function*) ;? (prn function*!factorial) (run 'main) |