这是我参与「第五届青训营 」笔记创作活动的第12天
C5 cpu Scheduling
Minimize response time Maximize Throughout Fairness share CPU amony user in a equtiable way
CPU utilization
Turnaround time of a process
Waiting time of a process
nonpreemptive preemptive FCFS 、Round Robin(RR) Scheduling、SRTF priority scheduling can be either preemptive or non-preemptive Multiple level scheduling Hard-real time systems Requires to complete a critical task within a guaranteed amount of time. Missing a deadline is a total system failure. Soft real-time systems can miss some deadline,but eventually performance will degrade if too many are missed.
C6 Process synchronization
对应编程题
Race condition
access and manipulate shared data concurrently.The final value of share data depends on which process .
Atomic Operation
Mutal exclusion
ensuring that only one process does a particular thing at once.
critial section
piece of code only one process can be executed at once.only one process at time can be get into the code.
what is semaphore(信号量)
A Semaphore has a non-negative integer value and support the following two operations.
Binary semaphore:integer value can range only between 0 and 1;can be simpler to implement,also known as mutex locks.
Counting semaphore: integer value can range over an unretricted domain.
Deadlock
Strarvation
How to use semaphere to solve the problem?
- determine concurrent and sequential operations.
- determine the rules of mutual exclusion and synchronization.
- determine the procedure of mutual exclusion and synchronization.
- determine the number and meaning of semaphores.
- determine the inital value of the semaphores.
- determine the position of P and V operations.
whenever a process need a block
classical synchronization problems Bound buffer problem Reader and writer problem Dining-Philosophers problem sleeping barber problem
C7 Deadlocks
four requirements for deadlocks
Mutual exclusion
Hold and wait
No preemption
Circular wait
deadlock aviodance
deadlock prevention
How the Banker's algorithm works?
1 let work and finish be vectors of length m and n,respectively Initialize: a.work=available b.finish[i]=flase for i=o.1...i-1 2.find an i such that both: a.finish[i]=false b.needi<=work if no such i exists,go to step 4. 3.work=work+allocationi finish[i]=true go to step 2. 4.If finish[i]==true for all i.then the system is in a safe state. 不能只写序列,要写计算过程。 if there is no enough for process B,unsafe state. Resource-request algorithm for process Pi. Requsti=requst vector for process Pi.