If transaction A holds a shared lock R and if transaction B also requests for…

2018

If transaction A holds a shared lock R and if transaction B also requests for a shared lock on R, it will

  1. A.

    result in a deadlock situation

  2. B.

    immediately be granted

  3. C.

    immediately be rejected

  4. D.

    be granted as soon as it is released by A

Attempted by 6 students.

Show answer & explanation

Correct answer: B

In two-phase locking (2PL), a lock manager grants a new lock request on a data item only if the requested lock mode is compatible with every lock already held on that item. Shared (S) locks are compatible with other shared locks, since both permit only reading; a shared lock is incompatible with an exclusive (X) lock, and an exclusive lock is incompatible with any other lock, because writing must not overlap with another read or write.

Application:

  1. Transaction A currently holds a shared lock on R.

  2. Transaction B requests a shared lock on the same item R.

  3. Checking the compatibility rule for the pair (shared held, shared requested): the two shared locks are compatible with each other.

  4. Since no conflict exists between A's held lock and B's requested lock, the lock manager grants B's request straight away, without placing B in a wait queue.

Cross-check: Compare this with a request that is NOT shared-shared — for instance, if B instead asked for an exclusive lock on R, or if A already held an exclusive lock, the pair would be incompatible, and B would have to wait until A's lock on R is released before its request could be granted. That queue-then-grant behaviour only arises for an incompatible pair; it does not apply to the shared-shared pair in this item, which independently confirms that B's request faces no conflict here.

Result: B's shared-lock request on R is granted immediately.

Explore the full course: Up Lt Grade Assistant Teacher 2025

Loading lesson…