Monday 25 February 2008

Petri-net solves deadlock

Using Petri net design a system usually in some ways:
1) Deny mutual exclusion
It changes the properties of the resources to let them be sharable. For example, printer spooler provides a sharable buffer which is a temporary working area to keep the documents. And then printer pulls off the documents from the buffer to print them one by one. So users do not need to wait for printing and they can do some other operations on computer. Also if there are a lot of jobs need to print, the jobs will in a queue in the buffer. Users do not need to wait for to print next one by themselves.
But changing properties of resources is mostly impossible.

2) Deny no pre-emption of allocated resources
In a system, if any items can not be obtained, release all the resources it holds. And then transaction waits and tries again to obtain the items it needs and locks them. This is to let other transactions finish their jobs first. Obviously, this limits concurrency.

3) Do not request while holding resources
A transaction can request the resources successfully if it holds no resources. This requests all transaction must release the resources which are held by them before they request a new one. Obviously, a transaction can not hold more than one resource. So, in the system, many transactions must waiting for the resource they need. If one kind of resources are very popular in the system that means many transactions need them or transactions need many of those resources, these resources must be waited for a long time or they must very often to wait for them. It may occur a problem – starvation (a transaction can not proceed for an indefinite period of time because it can not gain the resources).

4) Lineate requests - breaks cycles
All transactions using resources must be in order. For example in Figure 3, if A and B want to record and request CD and recorder, they must at first request CD, if successful, request recorder next. So there would not be deadlock happen.

In prevention, denying mutual exclusion and no pre-emption of allocated resources are not usually possible. Because there are not many resources can be changed property and no pre-emption is either few. Do not request while holding resource and lineate requests cause more waiting and the resources can not be used well. However, there is no deadlock.

No comments: