Beruflich Dokumente
Kultur Dokumente
multi-processor machine
Spin or yield?
CS 256/456 Multi-processor synchronization.
A process is waiting for an event, triggered by another
Dept. of Computer Science, University of Rochester process.
Should it spin wait or yield the processor?
2/8/2006 CSC 256/456 - Spring 2006 1 2/8/2006 CSC 256/456 - Spring 2006 2
…,
P1 P2 Pn–1 is waiting for a resource that is held by Pn,
wait (A); wait(B) and Pn is waiting for a resource that is held by P0.
wait (B); wait(A)
2/8/2006 CSC 256/456 - Spring 2006 3 2/8/2006 CSC 256/456 - Spring 2006 4
Reasonable if
Ensure that the system will never enter a deadlock state.
deadlocks occur very rarely
cost of prevention is high
Allow the system to enter a deadlock state and then
detect/recover. Your typical OSes take this approach
2/8/2006 CSC 256/456 - Spring 2006 5 2/8/2006 CSC 256/456 - Spring 2006 6
2/8/2006 CSC 256/456 - Spring 2006 7 2/8/2006 CSC 256/456 - Spring 2006 8
when a process holding some resources and waiting for System is in safe state if there exists a safe sequence of all
others, its resources may be preempted to be used by processes.
others
Problem Sequence <P1, P2, …, Pn> is safe if for each Pi, the resources that
Pi can still request can be satisfied by currently available
Many resources may not allow preemption; i.e., preemption resources + resources held by all the Pj, with j<i.
will cause process to fail If Pi resource needs are not immediately available, then Pi can wait
until all Pj have finished.
Attacking the Circular Wait Condition: When Pj is finished, Pi can obtain needed resources, execute, return
2/8/2006 CSC 256/456 - Spring 2006 9 2/8/2006 CSC 256/456 - Spring 2006 10
2/8/2006 CSC 256/456 - Spring 2006 11 2/8/2006 CSC 256/456 - Spring 2006 12
Safety check
repeat
pick any process that can finish with existing available
resources; finish it and release all its resources
until no such process exists
If graph contains no cycles ⇒ safe all finished → safe; otherwise → unsafe.
If graph contains a cycle ⇒
if only one instance per resource type, then unsafe.
if several instances per resource type, possibility of deadlock. When a resource request is made, the process
must wait if:
2/8/2006 CSC 256/456 - Spring 2006 13 2/8/2006 CSC 256/456 - Spring 2006 14
no enough available resource this request
2/8/2006 CSC 256/456 - Spring 2006 19 2/8/2006 CSC 256/456 - Spring 2006 20