about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/.traces/scheduler_interleaves_routines44
-rw-r--r--cpp/020run.cc1
-rw-r--r--cpp/038scheduler.cc27
3 files changed, 70 insertions, 2 deletions
diff --git a/cpp/.traces/scheduler_interleaves_routines b/cpp/.traces/scheduler_interleaves_routines
new file mode 100644
index 00000000..e8147b0e
--- /dev/null
+++ b/cpp/.traces/scheduler_interleaves_routines
@@ -0,0 +1,44 @@
+parse/0: instruction: 29
+parse/0:   ingredient: {name: "f2", value: 0, type: 0, properties: ["f2": "recipe"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
+parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
+parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "4", value: 0, type: 0, properties: ["4": "literal"]}
+parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "4", value: 0, type: 0, properties: ["4": "literal"]}
+parse/0:   product: {name: "4", value: 0, type: 1, properties: ["4": "integer"]}
+after-brace/0: recipe f1
+after-brace/0: run ...
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: recipe f2
+after-brace/0: copy ...
+after-brace/0: copy ...
+new/0: routine allocated memory from 1000 to 101000
+schedule/0: f1
+run/0: instruction f1/0
+run/0: ingredient 0 is f2
+new/0: routine allocated memory from 101000 to 201000
+schedule/0: f2
+run/0: instruction f2/0
+run/0: ingredient 0 is 4
+mem/0: storing 4 in location 3
+schedule/0: f1
+run/0: instruction f1/1
+run/0: ingredient 0 is 0
+mem/0: storing 0 in location 1
+schedule/0: f2
+run/0: instruction f2/1
+run/0: ingredient 0 is 4
+mem/0: storing 4 in location 4
+schedule/0: f1
+run/0: instruction f1/2
+run/0: ingredient 0 is 0
+mem/0: storing 0 in location 2
+schedule/0: f2
+schedule/0: f1
diff --git a/cpp/020run.cc b/cpp/020run.cc
index 178ff506..e43085e2 100644
--- a/cpp/020run.cc
+++ b/cpp/020run.cc
@@ -70,7 +70,6 @@ void run_current_routine()
     }
     ++current_step_index();
   }
-  Current_routine = NULL;
 }
 
 //: Some helpers.
diff --git a/cpp/038scheduler.cc b/cpp/038scheduler.cc
index 74d05582..d35d853d 100644
--- a/cpp/038scheduler.cc
+++ b/cpp/038scheduler.cc
@@ -1,7 +1,7 @@
 //: Run a second routine concurrently using fork, without any guarantees on
 //: how the operations in each are interleaved with each other.
 
-:(scenario run_multiple)
+:(scenario scheduler)
 recipe f1 [
   run f2:recipe
   1:integer <- copy 3:literal
@@ -26,6 +26,8 @@ ninstrs++;
 :(before "End Globals")
 list<routine*> Running_routines, Completed_routines;
 size_t Scheduling_interval = 500;
+:(before "End Setup")
+Scheduling_interval = 500;
 :(replace{} "void run(recipe_number r)")
 void run(recipe_number r) {
   Running_routines.push_back(new routine(r));
@@ -38,6 +40,7 @@ void run(recipe_number r) {
       Completed_routines.push_back(Current_routine);
     else
       Running_routines.push_back(Current_routine);
+    Current_routine = NULL;
   }
 }
 
@@ -60,3 +63,25 @@ case RUN: {
   Running_routines.push_back(new routine(Recipe_number[current_instruction().ingredients[0].name]));
   break;
 }
+
+:(scenario scheduler_interleaves_routines)
+% Scheduling_interval = 1;
+recipe f1 [
+  run f2:recipe
+  1:integer <- copy 0:literal
+  2:integer <- copy 0:literal
+]
+recipe f2 [
+  3:integer <- copy 4:literal
+  4:integer <- copy 4:literal
+]
++schedule: f1
++run: instruction f1/0
++schedule: f2
++run: instruction f2/0
++schedule: f1
++run: instruction f1/1
++schedule: f2
++run: instruction f2/1
++schedule: f1
++run: instruction f1/2