Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deadlock situation in threads?

want to know what is deadlock condition in threads, because in many of the books i studied how to avoid deadlock situation, i just want to know what is deadlock situation and a example code for that?

like image 985
Hariharbalaji Avatar asked Jan 04 '10 06:01

Hariharbalaji


1 Answers

Deadlock is a situation that a concurrent program cannot proceed.

A thread is waiting for another thread, while the other thread is waiting for the first thread's completion.

The commonly used real world example is a traffic flow.

alt text

No traffic can move until the other queue moves.

You may find a good discussion on deadlocks here.

Update : This is one java example I found on web (Oreilly book). It has comments on that so you can understand it easily.

Dining Philosophers problem is another good example to understand the deadlocks.

removed dead Imageshack link

Dead lock detection and Deadlock prevention are two of related areas that might be useful while learning about the deadlocks.

like image 76
Chathuranga Chandrasekara Avatar answered Nov 15 '22 10:11

Chathuranga Chandrasekara