The 2nd thread can be called without having the need to wait for the 1st thread to finish.The second thread should call getLocks(obj1, obj2)
When the 2nd thread calls getLocks(obj1, obj2) and it's assumed that an OS lets it quickly "follow" the 1st thread, it will have to wait for the the 1st thread to finish as the 1st thread goes into getLocks() and both obj1 and obj2 are locked, i.e. the 1st thread "owns" them.
When the 1st thread finishes, it releases both obj1 and obj2 and the 2nd thread will then go in.
Is my understanding correct? Thanks.
Schmichael
P. S.
This is also an equally valid way/answer to avoid a deadlock, isn't it?The second thread should call getLocks() only after first thread exits out of it.