Amazon interview question

How to solve the dead lock problem? write the code for example.