Search code examples
schedulingdeadlockround-robin

Round-robin scheduling and deadlock


Does round-robin scheduling ever cause deadlock? What happens if the CPU scheduling is based on round-robin and at one point in the schedule two different processes request the same file that no process owns? Would that cause deadlock or would the file be given to the process that is supposed to execute in the next step of the schedule?


Solution

  • The case you describe will not cause deadlock. Locks are atomic, so only one process can hold one at a time. Thus, whichever process has control at the time will acquire the lock and the second process will fail.

    However, in a more general case, deadlock can occur in RR scheduling. Consider two processes and two locks. Process A acquires lock 1 and then yields the processor to Process B. Process B then acquires lock 2 and attempts to acquire lock 1. Because lock 1 belongs to Process A, process B will then sleep. Process A awakes and attempts to acquire lock 2. Lock 2 still belongs to process B, so neither process can move forward and you have a deadlock.