Search code examples
bankers-algorithm

Banker's algorithm solution for given system state


I have final test in OS Course, in the morning tomorrow, and I got stuck with an problem.

Say we have 4 processes in our system: P1, P2, P3, P4, and 4 different resources: R1, R2, R3, R4. Current state of the system shown in this picture.

enter image description here

The question is - "Is system in deadlock or not?" I solved few similar problems, so, I think, the system IS in deadlock, because there aren't enough available resources (for example P4 requests 2 instances of R3, but in available list exists only 1 resource of R3).

I'm little confused because answer of my practitioner is : system isn't in deadlock, and processes running in this order: P4->P3->P1->P2

Which Solution is Right?

Thanks.


Solution

  • Your instructor is correct. In particular, P4 already has (1 0 1 1), and thus needs only (0 0 1 0), which can be easily met by the available resources. After P4 is served the resources, it completes and releases everything it was using (including its Current Allocation). The OS can then send those resources through to the remaining processes (in the correct sequence), thus no deadlock.