Question

Why we need banker's algorithm when we have locks,completion variables and semaphores.Since locks are acquired in linux in definite order,there can't be any deadlocks.So what is the use of running banker's algorithm in such situation.

Was it helpful?

Solution

Banker algorithm is used to avoid deadlock by checking whether a resource allocation may cause the system to be deadlock or not, while the lock is used to solve the critical section problem, i.e., to avoid more than one process can enter the critical section at the same time.

Locking itself cannot avoid/prevent deadlock without combining with other deadlock solutions.

And as deviantfan's comment: no restriction on the lock acquisition in most of the OSs. The following is a simple example in which the system may be deadlock even the use of lock is valid:

P1: ....; lock(fileA); lock(fileB); .... unlock(fileA); unlock(fileB); ....

P2: ....; lock(fileB); lock(fileA);..... unlock(fileB); unlock(fileA); ....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top