Alright so I would suggest you look at the code snippet given before this (Figure 7.4).
After you have understood that consider the code snippet in your query:
void transaction(Account from, Account to, double amount)
{
mutex lock1, lock2;
lock1 = get lock(from);
lock2 = get lock(to);
acquire(lock1);
acquire(lock2);
withdraw(from, amount);
deposit(to, amount);
release(lock2);
release(lock1);
}
Here unlike the 'actual' method of giving the resources an order (such as F(mutex_1) = 1, F(mutex_2) = 2 ) we give the ordering dynamically in the above code snippet here:
lock1 = get lock(from);
lock2 = get lock(to);
Now look at the function calls:
transaction(checking account, savings account, 25);
transaction(savings account, checking account, 50);
Look at the first two parameters of both transactions very carefully.
In the first transaction the call would be something like this:
lock1 = get lock(checking account); (assume this initializes lock1 as '1')
lock2 = get lock(savings account); (assume this initializes lock2 as '2')
Do the same for the 2nd transaction and you will see that the second transaction will try to acquire lock in the order 2,1 which is what we're trying to avoid using "lock ordering". This is equivalent to the code snippet I asked you to read before.