Then process B tries to open file X for writing. However, process B cannot succeed because process A already
has file X open. Now both processes are blocked indefinitely. A deadlock has occurred; the processes are locked
in a deadly embrace.
Four conditions are necessary for deadlock to occur:
1 Mutual exclusion
2 Hold and wait
3 No preemption
4 Circular wait
By mutual exclusion, we mean that resources are allocated exclusively to one process or another (and
throughout this discussion you can substitute ???thread??? for ???process???). If, in the example at the start of this
section, the files had been opened in shared mode, mutual exclusion would not apply, and the deadlock would
not occur.
By hold and wait, we mean that a process can continue to hold exclusive access to a resource even as it
waits to acquire another. If either process in the example had been compelled to release any file it had locked
when it requested exclusive access to another file, the deadlock would not occur.
By no preemption, we mean that the operating system will not force the release of a resource from
a blocked process in order to satisfy a demand by another process. If, in the example, the operating system
had forced blocked process A to release its control of file X in order to grant access to file X to process B, the
deadlock would not occur.
Pages:
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301