Barclays Interview Question

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