about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/020run6
-rw-r--r--cpp/038scheduler19
2 files changed, 23 insertions, 2 deletions
diff --git a/cpp/020run b/cpp/020run
index 456d578a..3e993f95 100644
--- a/cpp/020run
+++ b/cpp/020run
@@ -44,9 +44,11 @@ void run(recipe_number r) {
   run(routine(r));
 }
 
-void run(routine rr) {
+void run(routine rr)
+{  // curly on a separate line, because later layers will modify signature
   Current_routine = &rr;
-  while (!done(rr)) {
+  while (!done(rr))  // later layers will modify condition
+  {
     // Running One Instruction.
     vector<instruction>& instructions = steps(rr);
     size_t& pc = running_at(rr);
diff --git a/cpp/038scheduler b/cpp/038scheduler
new file mode 100644
index 00000000..3196795c
--- /dev/null
+++ b/cpp/038scheduler
@@ -0,0 +1,19 @@
+//: Run multiple routines concurrently, without any guarantees on how the
+//: operations in each are interleaved with each other.
+
+:(before "End Globals")
+size_t Scheduling_interval = 500;
+
+//: first, add a deadline to run()
+//: todo: these changes are ugly and brittle
+:(replace{} "void run(recipe_number r)")
+void run(recipe_number r) {
+  run(routine(r), Scheduling_interval);
+}
+:(replace "void run(routine rr)")
+void run(routine rr, size_t time_slice)
+:(replace "while (!done(rr))" following "void run(routine rr, size_t time_slice)")
+size_t ninstrs = 0;
+while (!done(rr) && ninstrs < time_slice)
+:(after "Running One Instruction")
+ninstrs++;