Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 26 CPU Simulator II
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts The event loop NextEventSimulator eventQ; initialize_event_queue(eventQ, otherData); Event *theEvent; theEvent = eventQ.nextEvent( ); while (theEvent != NULL) { handleEvent(theEvent, otherData); theEvent = eventQ.nextEvent( ); }
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts Handling events We will write this code in class.
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts Keeping Track of Variables It's a good idea to make lists of variables that you will need to update and keep track of in your program. We will start a list now, and add to it as needed while we design our functions. Process variablesSimulation variables
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts Helpful Hint Use a class or struct to keep all your process variables together. Use a class or struct to keep all your simulation variables together. This makes parameter passing easier. (You will lose points for relying on global variables!) Use enums to make lists of integers more readable (e.g. process states, CPU states, etc.)
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts handle_new_ready( ) We will determine what needs to be done for this function in class.
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts handle_ready_run( ) We will determine what needs to be done for this function in class.
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts handle_run_term( ) We will determine what needs to be done for this function in class.
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts handle_run_block( ) We will determine what needs to be done for this function in class.
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts handle_block_ready( ) We will determine what needs to be done for this function in class.
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts Files, etc. Place all the code for the fcfs simulation in the file"fcfs.cc" In driver.cc, you should have an include line: #include "fcfs.cc" To compile, you can type: g++ driver.cc -o sim Place all struct definitions and enums in a file "sim.h" Include "sim.h" in both driver.cc and fcfs.cc You will need to use #ifndef SIM_H, etc. to make sure the linker doesn't complain. Use the following include lines in sim.h: #include "nextEvent.h" #include "list.h" Do not include nextEvent.h or list.h in driver.cc or fcfs.cc
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, Operating System Concepts Developing your code Write your functions one at a time. Debug each function before you start working on the next. Example: Make sure your function to initialize the Event queue inserts all the appropriate events based on the process arrival times before you try to right any of the event handlers. Use cout statements and the display( ) function (part of the NextEventSimulator and the list classes) to make sure your function is doing the right thing.