thread_lock(global);
thread_lock(locks[id1]);
thread_lock(locks[id2]);
thread_unlock(global);
<transfer money>
thread_lock(global);
thread_unlock(locks[id1]);
thread_unlock(locks[id2]);
thread_unlock(global);
Consider the following example
Thread 1
1. thread_lock(global);
2. thread_lock(locks[1]);
3. thread_lock(locks[2]);
4. thread_unlock(global);
Thread 2
5. thread_lock(global);
6. thread_lock(locks[3]);
7. thread_lock(locks[2]); // Thread 2 will block here
... Thread 2 is still holding the "global" lock.