Barclays interview question

how would you avoid deadlock in C++? Write the code for all solutions.