DIR Return Create A Forum - Home
---------------------------------------------------------
ifaq
HTML https://ifaq.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: Common operating systems related questions
*****************************************************
#Post#: 25--------------------------------------------------
Deadlock prevention
By: avinash.srin Date: August 26, 2011, 6:44 am
---------------------------------------------------------
What is a deadlock and how do you overcome it?
#Post#: 26--------------------------------------------------
Re: Deadlock prevention
By: avinash.srin Date: August 26, 2011, 6:46 am
---------------------------------------------------------
A lock occurs when multiple processes try to access the same
resource at the same time.
One process loses out and must wait for the other to finish.
A deadlock occurs when the waiting process is still holding on
to another resource that the first needs before it can finish.
So, an example:
Resource A and resource B are used by process X and process Y
X starts to use A.
X and Y try to start using B
Y 'wins' and gets B first
now Y needs to use A
A is locked by X, which is waiting for Y
Deadlocks can be avoided by:
1. Narrow down the synchronization's scope to as small a block
as possible.
2. Try to avoid locking multiple objects if possible.
3. Use a consistent lock order, by which if multiple locks need
to be acquired will be acquired in a particular predefined
order.
4. Maintain a proper documentation about the order, and other
locking strategy if used.
*****************************************************