CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11:30 - 12:30 AM
Lecture 24 – Wednesday, March 13, 2013 Last time: CPU Scheduling Today: CPU scheduling Next time Process synchronization Reading assignments Chapter 6 of the textbook Lecture 24
Comparison of FCFS, SJF, and RR We have three processes A, B, and C. Each process is characterized by Release time (R) – the time the process arrives in the system Start time (S) – the time the scheduler allows it to run Wait time (W) – the time till it has to wait until it is started: W = S - R Work (Wrk) – the amount of time it needs to use the CPU Finish time (F) – the time the process finishes: F=S+Wrk Time in system (T) – the time from when the process arrives until it finishes: T = F- R. We compare The average time in system The average waiting time for three scheduling policies: FCFS, SJF, and RR. Lecture 24
Proc Release time Work Start time Finish time Wait time till start Time in system A 3 B 1 5 3 + 5 = 8 3 – 1 = 2 8 – 1 = 7 C 2 8 8 + 2 = 10 8 – 3 = 5 10 – 3 = 7 A 3 B 1 5 5 + 5 = 10 4 10 – 1 = 9 C 2 3 + 2 = 5 5 – 3 = 2 A 3 6 6 – 0 = 6 B 1 5 10 1 – 1 = 0 10 – 1 = 9 C 2 8 5 – 3 = 2 8 – 3 = 5 Lecture 24
Average waiting time till the job started Average time in system Scheduling policy Average waiting time till the job started Average time in system FCFS 7/3 17/3 SJF 4/3 14/3 RR 3/3 20/3 Lecture 24
Priority scheduling Each thread/process has a priority and the one with the highest priority (smallest integer highest priority) is scheduled next. Preemptive Non-preemptive SJF is a priority scheduling where priority is the predicted next CPU burst time Problem Starvation – low priority threads/processes may never execute Solution to starvation Aging – as time progresses increase the priority of the thread/process Priority my be computed dynamically Lecture 24
Priority inversion other types of software. A lower priority thread/process prevents a higher priority one from running. T3 has the highest priority, T1 has the lowest priority; T1 and T3 share a lock. T1 acquires the lock, then it is suspended when T3 starts. Eventually T3 requests the lock and it is suspended waiting for T1 to release the lock. T2 has higher priority than T1 and runs; neither T3 nor T1 can run; T1 due to its low priority, T3 because it needs the lock help by T1. Allow a low priority thread holding a lock to run with the higher priority of the thread which requests the lock other types of software. Lecture 24