about summary refs log blame commit diff stats
path: root/cpp/038scheduler
blob: 5ca6cbdc43e28c5dfb38e20127336bd7a3e09248 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                                         


                                           
 


                                                                                    
                   
                                       

                                  
//: 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) {
  routine rr(r);
  Current_routine = &rr;
  run_current_routine(Scheduling_interval);
}
:(replace "void run_current_routine()")
void run_current_routine(size_t time_slice)
:(replace "while (!done())" following "void run_current_routine(size_t time_slice)")
size_t ninstrs = 0;
while (!done() && ninstrs < time_slice)
:(after "Running One Instruction")
ninstrs++;