diff options
-rw-r--r-- | mu.arc | 47 | ||||
-rw-r--r-- | mu.arc.t | 17 |
2 files changed, 36 insertions, 28 deletions
diff --git a/mu.arc b/mu.arc index 420201f7..b2c44be4 100644 --- a/mu.arc +++ b/mu.arc @@ -85,7 +85,7 @@ (= traces* (queue))) (def new-trace (filename) - (prn "new-trace " filename) +;? (prn "new-trace " filename) (= curr-trace-file* filename)) (= dump-trace* nil) @@ -102,6 +102,10 @@ (do1 nil (apply trace "-" args))) +(def tr2 (msg arg) + (tr msg arg) + arg) + (def check-trace-contents (msg expected-contents) (unless (trace-contents-match expected-contents) (prn "F - " msg) @@ -209,23 +213,31 @@ ; wake up any necessary sleeping routines (either by time or on a location) ; detect deadlock: kill all sleeping routines when none can be woken (def update-scheduler-state () - (if (~empty routine*) - (enq routine* running-routines*) +;? (tr "00 " routine*) +;? (tr "01 " empty.routine*) + (if + rep.routine*!sleep + (do (trace "schedule" "pushing " top.routine*!fn-name " to sleep queue") + (set sleeping-routines*.routine*)) + (~empty routine*) + (do ;(trace "schedule" "scheduling " top.routine*!fn-name " for further processing") + (enq routine* running-routines*)) :else - (push routine* completed-routines*)) + (do ;(trace "schedule" "done with " routine*) + (push routine* completed-routines*))) + (= routine* nil) +;? (tr "bb " sleeping-routines*) (each (routine _) canon.sleeping-routines* - (when (> curr-cycle* rep.routine!sleep.1) +;? (tr "cc " sleeping-routines*) + (when (> curr-cycle* rep.routine!sleep.0) (trace "schedule" "waking up " top.routine!fn-name) (wipe sleeping-routines*.routine) ; do this before modifying routine (wipe rep.routine!sleep) (++ pc.routine) (enq routine running-routines*))) +;? (tr "zz") ) -;? (while (or (~empty running-routines*) -;? (~empty sleeping-routines*)) -;? (detect-deadlock) -;? (point continue ;? (each (routine _) canon.sleeping-routines* ;? (awhen (case rep.routine!sleep.1 ;? literal @@ -233,24 +245,11 @@ ;? ;else ;? (aand (m rep.routine!sleep) ;? (~is it 0))) -;? ;? (prn running-routines*) -;? (detect-deadlock) ;? (when (empty running-routines*) ;? ; ensure forward progress ;? (trace "schedule" "skipping cycle " curr-cycle*) ;? (++ curr-cycle*) ;? (continue)) -;? ; simple round-robin scheduler -;? (= routine* deq.running-routines*) -;? (trace "schedule" top.routine*!fn-name) -;? (routine-mark:run-for-time-slice scheduling-interval*) -;? (if rep.routine*!sleep -;? (do (trace "schedule" "pushing " top.routine*!fn-name " to sleep queue") -;? (set sleeping-routines*.routine*)) -;? (~empty routine*) -;? (enq routine* running-routines*) -;? :else -;? (enq-limit routine* completed-routines*)) ;? ))) (def detect-deadlock () @@ -1006,10 +1005,6 @@ (on-init (= traces* (queue))) -(def prn2 (msg . args) - (pr msg) - (apply prn args)) - (def canon (table) (sort (compare < [tostring (prn:car _)]) (as cons table))) diff --git a/mu.arc.t b/mu.arc.t index d023d2f9..58ac2d3a 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -152,6 +152,7 @@ (add-fns '((main ((1 integer) <- copy (23 literal))))) +;? (set dump-trace*) (run 'main) ;? (prn memory*) (if (~is memory*.1 23) @@ -1732,10 +1733,14 @@ (assert (is 1 len.running-routines*)) ; sleeping routine (let routine make-routine!f2 - (= rep.routine!sleep '(literal 23)) + (= rep.routine!sleep '(23 literal)) (set sleeping-routines*.routine)) ; not yet time for it to wake up (= curr-cycle* 23) +; pretend we just finished a routine +(= routine* (annotate 'routine (table))) +;? (set dump-trace*) +;? (= dump-trace* (obj whitelist '("run" "schedule"))) (update-scheduler-state) (if (~is 1 len.running-routines*) (prn "F - scheduler lets routines sleep")) @@ -1752,10 +1757,12 @@ (assert (is 1 len.running-routines*)) ; sleeping routine (let routine make-routine!f2 - (= rep.routine!sleep '(literal 23)) + (= rep.routine!sleep '(23 literal)) (set sleeping-routines*.routine)) ; time for it to wake up (= curr-cycle* 24) +; pretend we just finished a routine +(= routine* (annotate 'routine (table))) (update-scheduler-state) (if (~is 2 len.running-routines*) (prn "F - scheduler wakes up sleeping routines at the right time")) @@ -2228,6 +2235,12 @@ (prn "F - channels are meant to be shared between routines")) ;? (quit) +;? (reset) +;? (new-trace "channel-race") +;? (add-fns +;? '((reader +;? (( + ;; Separating concerns ; ; Lightweight tools can also operate on quoted lists of statements surrounded |