Keshav
Posts: 11
Nickname: kesh
Registered: Aug, 2002
|
|
Re: whats a deadlock ?and where and when does it happen??and how to rectify it?
|
Posted: Aug 19, 2002 5:58 AM
|
|
Hi Senthil,
Before we come across the meaning of Deadlock .. Well u know that a printer is a shared device. When one job is printed the other's cannot print it unless & untill it completes.
Same way when we have a thread which calls on a sycrhonized method. We say it enters the monitor. Unless & untill the Thread completes the execution no other thread can enter the monitor( I mean call the method)
U will be having many resources like the printer to be shared.
Now assume that u have two resources A & B, U also have two threads X & Y. X calls on a <b>synchronized </b>method & enters the monitor A which is holding the resource A. Just after that Thread Y calls another <b> synchronized </b> method which enters another monitor B which is holding the resource B.
Hope ur clear with this. Now we have a stituation where the both the threads have entered the monitor. Now Thread A needs to make use of the resuorce which is presently occupied by Thread B. So it waits for Thread B to come out of the monitor. Thread B which cannot complete the task bcoz it needs the resource which is occupied by Thread A. So it also waits.
Both the threads are in wait state. This waiting will never get over. This is called DEAD LOCK
There is no solution for Dead Lock, while coding the programmer has to carefully handle the code in such a way that deadlock doesn't exits.
Hope ur clear with the explanation
<i><b>Cheeeeeeeeeeers
Keshav</b></i>
|
|