Resources
Deadlocks can occur when processes have been granted exclusive access to devices, files and so forth. To make the discussion of deadlocks as general as possible, we will refer to the objects granted as resources. A resources can be a hardware device (e.g. , a tape drive) or a piece of information (e.g., a locked record in the database). A computer will normally have many different resources that can be acquire. A resourece is anything that can be used by only a single process at any instant of time.
· Preemptable and Nonpreemptable Resource
Resources come in two types: Preemptable and Nonpreemptable. A Preemptable resource is one that can be taken away from the process owning it with no ill effects.
Memory is an example of a Preemptable resource. Consider, for example, a system with 32 MB of user memory, one printer, and two 32-MB processes that each want to print something. Process A request and gets the printer, then start to compute the values to print. Before it has finished with the computation, it exceeds its time quantum and is swapped out.
Process B now runs and tires, unsuccessfully, to acquire the printer. Potentially, we now have a deadlock situation, because A has the printer and B has the memory, and neither can proceed without the resource held by the other. Fortunately, it is possible to preempt (take away) the memory from B by swapping it out and swapping A in. Now A can run, do its printing, and then release the printer. No deadlock occurs.
A Nonpreemptable resource, in contrast is one that cannot be taken away from its current owner without causing the computation to fail. If a process has begun to burn a CD-ROM, suddenly taking the CD recorder away from it and giving it to another process will result in a garbled CD. CD recorders are not Preemptable at an arbitrary moment.