What is Deadlock? A dead-lock is a situation in which two devices or computer programs sharing the same resource are effectively stopping each other from accessing the resource. Final result in both programs closing to function.
The earliest device or computer operating systems (OS) ran only single program at a time. All of the resources of the system were available to this Single program. After operating systems ran multiple programs at once, its call multi-programming inter leaving them. Programs were want’s or required to specify in advance. What resources they require so that they could avoid (dodge) conflicts with other programs are running at the same time. Hereafter some operating systems offered dynamic allocation of resources. Programs could request to further allocations of resources after they had running. This led to the difficulty of the deadlock. Here is the simplest example:
Program A requests resource 1 and receives it.
Program B requests resource 2 and receives it.
Program A requests resource 2 and is queued up, pending the release of 2.
Program B requests resource 1 and is queued up, pending the release of 1.
Now no more programs can proceed until the other program are releases a resource. The operating system (OS) can’t know what action to take. At this point the only alternative is to abort (break) one of the programs.
Learn to contract with dead-locks had a major strike or impact on the development of OS and the structure of databases (DB). Data was structured and the order of requests was constrained in order to avoid creating deadlocks.
Deadlocks can be avoided by avoiding at least one of the four conditions, because all this four conditions are required simultaneously to cause deadlock.
Resources shared such as read-only files do not lead to deadlocks but resources, such as printers and tape drives, requires exclusive access by a single process.
In this condition processes must be prevented from holding one or more resources while simultaneously waiting for one or more others.
Preemption of process resource allocations can avoid the condition of deadlocks, where ever possible.
Circular wait can be avoided if we number all resources, and require that processes request resources only in strictly increasing(or decreasing) order.