Monday, March 26, 2012

making sense of deadlock

Example,
1) Two transactions, A and B have a Shared Lock on a resource
2) Both intend to update the resource
3) Transaction A comes in an places an Update lock on the resource
4) Transaction A then tries to do a Exclusive Lock on the resource.
Shouldnt step 4 cause a deadlock since Transaction B is waiting on A to
release its locks, while Transaction A is waiting on B to release the Shared
lock before it can place the Exclusive Lock on the same resource?
Im a little ... thanks for any insight.
GNo, it won't cause a deadlock. Obtaining the update lock ensures that only
Transaction A can transition to an exclusive lock on the resource in order t
o
perform the update. Obtaining the update lock ensures that Transaction A
doesn't have to wait for Transaction B to release its shared lock before it
can transition to an exclusive lock to perform the modification.
READ: "Understanding Locking in SQL Server" in books online.
"Girish" wrote:

> Example,
> 1) Two transactions, A and B have a Shared Lock on a resource
> 2) Both intend to update the resource
> 3) Transaction A comes in an places an Update lock on the resource
> 4) Transaction A then tries to do a Exclusive Lock on the resource.
> Shouldnt step 4 cause a deadlock since Transaction B is waiting on A to
> release its locks, while Transaction A is waiting on B to release the Shar
ed
> lock before it can place the Exclusive Lock on the same resource?
> Im a little ... thanks for any insight.
> G
>
>

No comments:

Post a Comment