Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid deadlocks?

When using multiple threads, shared memory needs to be locked by critical sections. However, using critical sections causes potential deadlocks. How can they be avoided?

like image 290
Dimitri C. Avatar asked Jun 29 '09 07:06

Dimitri C.


People also ask

What are the ways of dealing with deadlock?

There are four methods of handling deadlocks - deadlock avoidance, deadlock prevention, deadline detection and recovery and deadlock ignorance.

Which protocol is used to avoid deadlock?

Two-phase locking protocol is widely used in concurrent transaction database to ensure the correctness of concurrent scheduling. This paper presents a Petri net model for 2PL protocol, and then gives a deadlock prevention algorithm for 2PL protocol.

What are the causes of deadlock?

Deadlock occurs when a set of processes are in a wait state, because each process is waiting for a resource that is held by some other waiting process. Therefore, all deadlocks involve conflicting resource needs by two or more processes.


1 Answers

One way is to use a hierarchy of critical sections. If you ensure that a parent critical section is never entered within one of its children, deadlocks cannot happen. The difficulty is to enforce this hierarchy.

like image 111
Dimitri C. Avatar answered Oct 02 '22 04:10

Dimitri C.