第六章死锁精品.ppt
文本预览下载声明
* * * * * Only one thread at a time can acquire a spinlock. Any other thread attempting to acquire the same lock will keep trying (spinning) until it can acquire the lock. In essence a spinlock is built on an integer location in memory that is checked by each thread before it enters its critical section. If the value is 0, the thread sets the value to 1 and enters its critical section. If the value is nonzero, the thread continually checks the value until it is zero. The spinlock is easy to implement but has the disadvantage that locked-out threads continue to execute in a busy-waiting mode. Thus spinlocks are most effective in situations where the wait time for acquiring a lock is expected to be very short, say on the order of less than two context changes. * * Movie button goes to /~zhangd/oscal/Banker/Banker.html * * Animation: Callouts explain resource parts of figure This figure shows the state of a system consisting of four processes and three resources. Total amount of resources R1 = 9 R2 = 3 R3 = 6 In the current state allocations have been made to the four processes, leaving available 1 unit of R2 1 unit of R3 Is this a safe state? To answer this question, we ask an intermediate question: Can any of the four processes be run to completion with the resources available? That is, can the difference between the maximum requirement and current allocation for any process be met with the available resources? * * In this case, each of the remaining processes could be completed as shown on the next slides * * Suppose we choose P1, allocate the required resources, complete P1, and return all of P1’s resources to the available pool. We are left in the state shown in Figure 6.7c on this slide * * P3 completes, resulting in the state of Figure 6.7d shown on this slide Finally, we can complete P4. At this point, all of the processes have been run to completion. Thus, the state defined by Figure 6.7a is a safe state. * * Suppose t
显示全部