I learned that I should unlock reverse order to lock order.
For example.
A.lock();
B.lock();
B.unlock();
A.unlock();
But, what happen if I did like this :
A.lock();
B.lock();
A.unlock();
B.unlock();
I try to make a deadlock scenario,
but if I always lock A earlier then B, then I don’t know how deadlock would happen.
Would you help me?
Lock ordering just means that you prevent deadlocks by obtaining locks in a fixed order, and do not obtain locks again after you start unlocking.
I do not think the order of unlocks makes any difference here (in fact, it should be beneficial to release a lock as soon as possible, even if out of order)