1

I was going through the examples of deadlock exceptions online and found this link

As I understand, here we have two processes (session 1 and 2). The first one acquires lock on pd1, and second acquires on pd2. Then after that, first one want to read from pd2 and second one from pd1.

What I dont get is that why do we have a deadlock here. Wouldnt it work in a way that session updates and once it is done updating, it will release the lock on pd1, and with that session 2 will be able to read from pd1. Similarly the other way round? Why does the Update + Select has to be a single operation here?

Is it because they are part of the same transaction, hence within a transaction they wont let go of their locks acquired on any object?

3

Sybase ASE uses blocking locks for transaction isolation, meaning that readers block writers and writers block readers (unlike other databases which use versioning so that writers don't block readers and vice versa).

So each SELECT is blocked by the exclusive lock taken out by the earlier UPDATE on the table it is selecting from, since that update was done by a different session (it wouldn't block if it was the same session). Since neither SELECT can proceed now, there is a deadlock.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.