about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-10 05:42:56 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-10 05:42:56 -0700
commit00b808d947ca6a6844953c03df329b99db9d3856 (patch)
tree773ad72c2929980cc0def55bd05274e9ba1be331
parent45ca3bb7393d264db9817f5e7990cbd7561c058e (diff)
downloadmu-00b808d947ca6a6844953c03df329b99db9d3856.tar.gz
1318 - 1317 actually works now
-rw-r--r--038scheduler.cc45
-rw-r--r--042new.cc6
-rw-r--r--070display.cc1
3 files changed, 45 insertions, 7 deletions
diff --git a/038scheduler.cc b/038scheduler.cc
index 4f74bf3e..c67dfdae 100644
--- a/038scheduler.cc
+++ b/038scheduler.cc
@@ -4,10 +4,13 @@
 :(scenario scheduler)
 recipe f1 [
   start-running f2:recipe
-  1:integer <- copy 3:literal
+  # wait for f2 to run
+  {
+    loop-unless 1:integer
+  }
 ]
 recipe f2 [
-  2:integer <- copy 4:literal
+  1:integer <- copy 1:literal
 ]
 +schedule: f1
 +schedule: f2
@@ -51,6 +54,7 @@ void run(recipe_number r) {
     assert(Current_routine);
     assert(Current_routine->state == RUNNING);
     trace("schedule") << current_recipe_name();
+//?     trace("schedule") << Current_routine_index << ": " << current_recipe_name(); //? 1
 //?     trace("schedule") << Current_routine->id << " " << current_recipe_name(); //? 1
     run_current_routine(Scheduling_interval);
     // Scheduler State Transitions
@@ -171,6 +175,10 @@ recipe f2 [
 :(scenario start_running_takes_args)
 recipe f1 [
   start-running f2:recipe, 3:literal
+  # wait for f2 to run
+  {
+    loop-unless 1:integer
+  }
 ]
 recipe f2 [
   1:integer <- next-ingredient
@@ -219,18 +227,41 @@ recipe f1 [
 -run: idle
 
 //:: Routines are marked completed when their parent completes.
+
+:(scenario scheduler_kills_orphans)
+recipe main [
+  start-running f1:recipe
+  # f1 never actually runs because its parent completes without waiting for it
+]
+recipe f1 [
+  1:integer <- copy 0:literal
+]
+-schedule: f1
+
 :(before "End Scheduler Cleanup")
+//? trace("schedule") << "Before cleanup"; //? 1
+//? for (index_t i = 0; i < Routines.size(); ++i) { //? 1
+//?   trace("schedule") << i << ": " << Routines.at(i)->id << ' ' << Routines.at(i)->state << ' ' << Routines.at(i)->parent_index << ' ' << Routines.at(i)->state; //? 1
+//? } //? 1
 for (index_t i = 0; i < Routines.size(); ++i) {
   if (Routines.at(i)->state == COMPLETED) continue;
   if (Routines.at(i)->parent_index < 0) continue;  // root thread
-  if (has_completed_parent(i)) Routines.at(i)->state = COMPLETED;
+//?   trace("schedule") << "AAA " << i; //? 1
+  if (has_completed_parent(i)) {
+//?     trace("schedule") << "BBB " << i; //? 1
+    Routines.at(i)->state = COMPLETED;
+  }
 }
+//? trace("schedule") << "After cleanup"; //? 1
+//? for (index_t i = 0; i < Routines.size(); ++i) { //? 1
+//?   trace("schedule") << i << ": " << Routines.at(i)->id << ' ' << Routines.at(i)->state << ' ' << Routines.at(i)->parent_index << ' ' << Routines.at(i)->state; //? 1
+//? } //? 1
 
 :(code)
 bool has_completed_parent(index_t routine_index) {
-//?   cerr << routine_index << '\n'; //? 1
-  for (long long int j = routine_index; j < 0; j = Routines.at(j)->parent_index) {
-//?     cerr << ' ' << j << '\n'; //? 1
+//?   trace("schedule") << "CCC " << routine_index << '\n'; //? 2
+  for (long long int j = routine_index; j >= 0; j = Routines.at(j)->parent_index) {
+//?     trace("schedule") << "DDD " << j << '\n'; //? 2
     if (Routines.at(j)->state == COMPLETED)
       return true;
   }
@@ -300,7 +331,7 @@ Recipe_number["$dump-routines"] = _DUMP_ROUTINES;
 :(before "End Primitive Recipe Implementations")
 case _DUMP_ROUTINES: {
   for (index_t i = 0; i < Routines.size(); ++i) {
-    cerr << Routines.at(i)->id << ": " << Routines.at(i)->state << '\n';
+    cerr << i << ": " << Routines.at(i)->id << ' ' << Routines.at(i)->state << ' ' << Routines.at(i)->parent_index << '\n';
   }
   break;
 }
diff --git a/042new.cc b/042new.cc
index 375b4ce4..754091c8 100644
--- a/042new.cc
+++ b/042new.cc
@@ -118,11 +118,17 @@ recipe main [
 recipe f1 [
   start-running f2:recipe
   1:address:integer/raw <- new integer:type
+  # wait for f2 to complete
+  {
+    loop-unless 4:integer/raw
+  }
 ]
 recipe f2 [
   2:address:integer/raw <- new integer:type
   # hack: assumes scheduler implementation
   3:boolean/raw <- equal 1:address:integer/raw, 2:address:integer/raw
+  # signal f2 complete
+  4:integer/raw <- copy 1:literal
 ]
 +mem: storing 0 in location 3
 
diff --git a/070display.cc b/070display.cc
index b62cda37..f0e96f02 100644
--- a/070display.cc
+++ b/070display.cc
@@ -27,6 +27,7 @@ Recipe_number["return-to-console"] = RETURN_TO_CONSOLE;
 :(before "End Primitive Recipe Implementations")
 case RETURN_TO_CONSOLE: {
   tb_shutdown();
+//?   Trace_stream->dump_layer = "all"; //? 1
   break;
 }