• In this and following posts I am going to explain one of the most important issue of the operating system design called “Deadlock”.  It deals with the basic concept of deadlock, how it occurs and finally summing up with its possible solutions.
  • A system has a finite number of resources to be distributed among multiple processes.
  • These resources are of different types such as memory space, CPU cycles, files, I/O devices.
  • A system may have multiple instances of different resources. For example if a system has five printers, then the resource type printer has five instances.
  • If a process requests an instance of resource type then allocation of any instance of that resource type will satisfy the request.
  • Each process must request a resource before using it and must release after using it.
  • A process may request as many resources as it require to complete its task.
  • The number of resources should not exceed the total number of available resources. For example a process cannot request two disk drives if system has only one.
  • In normal operation mode, a process may utilize a resource only in the following sequences:
  1. Request: the process requests the resource. If that resource is not free, then the process has to wait until it becomes free.
  2. Use: After getting control of the desired resource, the process can use it. For example if the resource is printer, it can print on the printer.
  3. Release: the process releases the resource.
  • A system table keeps record about each allocated and free resources.
  • A system also keeps track of the different processes to which resources are allocated.
  • If the requested resource is allocated to other process then the process is added to the queue of processes waiting for that resource.
  • The resources may be either physical resources such as printer, memory, processor or logical resources such as files.
  • Suppose a system has three CD –RW drives and three processes each having CD-RW drive. Now if each process requests another drive, the process will be in a deadlock state.
  • This example describes the deadlock of the same resource type.
  • Deadlock may also occur for different resource type.
  • For example consider a system having one printer and one tap drive. Suppose tap drive is allocated to process p1 and printer is allocated to process p2. If process p1 requests the printer and process p2 requests the tap drive, then it creates a deadlock.

Deadlock Creation

  • In simple terms,

A system is said to be in a deadlock state if some processes are waiting for each other to release resources to complete their task.