A good start is to examine your critical code path. When you need to lock resources, make sure you are locking them in the same order at all points.
Then, if you cannot exclusively lock ALL resources, you need to release all the resources you have locked, then try again.
Next, be careful not to get into a live lock situation. A good method is to have a locking queue. If a process cannot get it's items then it joins a queue, when it comes to the front of the queue it is triggered to go and then it is its turn to lock and go.
I recently found a great resource on this,
here[
^].