Deadlock
Ordinarily, deadlock does not occur. However, it does occur when all of
the following conditions are met:
- A resource is held by only one process at a time. If processes can all have access to the resource at the same time, either there is no need to share the resource or the resource can be used by all processes — like electricity or read-only records.
- A resource can be released only by the process that acquired it.
- A process attempts to acquire (that is, hold) more than one shared resource at a time.
- A process can wait for a resource to be made available by another process. When two processes are waiting on resources held by each other, circular waiting, often referred to as deadlock, occurs.
When these conditions are combined, a resource can become unavailable.
The standard example is of two processes, each of which requires two tape
drives. When each process gets one tape drive and waits for the other, deadlock
occurs. To elaborate, suppose a system has only two tape drives:
- Each process holds a tape drive. The process has exclusive use of the tape drive until it releases the drive.
- Only the process holding the tape drive can release it.
- The tape drives are acquired one-at-a-time by the processes.
- The processes are going to wait until a second tape drive becomes available.
Of course, if both processes wait indefinitely, an attribute for being a process is lost, that is, terminated, and some currently held resources are not released in a finite time. Normally, it is not practical to expect a process to include a time-out facility to ensure that shared resources are released in a finite time. However, it is expected that there is an external mechanism that can time out a process when necessary.
Deadlock can be detected and eliminated with system timeouts and process deletions. The z/TPF system protects itself in these and other ways from deadly embrace.
See z/TPF Application Programming for more information about deadlock detection.