Event Class - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Event Class

Description:

case I/O completion. handle_IO_completion(e) break. case Timer expiration ... create a CPU completion event; add the new event into EQ; ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 9
Provided by: xiaoyu1
Category:

less

Transcript and Presenter's Notes

Title: Event Class


1
Event Class
  • Events class
  • class Event
  • public
  • int time //time event should take place
  • int type //type of event
  • int procId //process to which event belongs

2
Main Simulation Pseudocode
  • int main()
  • ...
  • quitTime 300 sec
  • initialize event queue EQ
  • currentTime 0
  • while (EQ is not empty currentTime lt
    quitTime)
  • e EQ.remove_next_event()
  • currentTime e.time
  • handle_the_event (e)
  • ...

3
Handle_the_event Pseudocode
  • handle_the_event (Event e)
  • Switch (e.type)
  • case process_arrival
  • handle_proc_arrival(e)
  • break
  • case CPU completion
  • handle_CPU_completion(e)
  • break
  • case I/O completion
  • handle_IO_completion(e)
  • break
  • case Timer expiration
  • handle_Timer_expiration(e)
  • break
  • schedular.run()

4
Handle Process arrival
  • Handle_proc_arrival(e)
  • proc e.procId
  • add proc to ready queue

5
Handle CPU Completion
  • Handle_CPU_completion (e)
  • proc e.procId
  • if (proc has completed its total time)
  • remove proc
  • else
  • generate a random IO burst length
  • create a IO completion event
  • add the new event into EQ

6
Handle I/O completion
  • Handle_IO_completion (e)
  • proc e.procId
  • generate the length of next CPU burst
  • add the proc to the ready queue

7
Handle Timer Expiration
  • Handle_timer_expiration
  • proc e.procId
  • move running proc to ready queue and update its
    CPU burst length

8
Scheduler Class
  • Class Scheduler
  • void run
  • if(CPU is idle)
  • select and dispatch a proc from ready queue
  • create a CPU completion event
  • add the new event into EQ
  • else if (preemptive scheduling and condition
    is true)
  • move the running proc to ready queue
  • select and dispatch a proc from ready queue
  • create a CPU completion event
  • add the new event into EQ
Write a Comment
User Comments (0)
About PowerShow.com