Published by: Zaya
Published date: 22 Jun 2021
In databases and transaction processing, two-phase locking (2PL) is a concurrency control method that guarantees serializability. It is also the name of the resulting set of database transaction schedules (histories). The protocol utilizes locks, applied by a transaction to data, which may block (interpreted as signals to stop) other transactions from accessing the same data during the transaction's life. By the 2PL protocol, locks are applied and removed in two phases:
Two types of locks are utilized by the basic protocol: Shared and Exclusive locks. Refinements of the basic protocol may utilize more lock types. Using locks that block processes, 2PL may be subject to deadlocks that result from the mutual blocking of two or more transactions.
In a non-resource deadlock, a deadlock occurs without the involvement of any resources. Say you have two nodes in a network that communicate and have a 3 steps handshake:
Both nodes are waiting for each other => deadlock
Starvation is the phenomenon in which a process is not able to acquire the desired resources (like processor, I/O device, etc) for a very long time to progress with its execution.
This can happen due to the drawbacks of scheduling algorithms. Scheduling algorithms are used to decide to which process the resource(s) needs to be given next.
Example:
Deadlock VS Starvation
Livelock occurs when two or more processes continually repeat the same interaction in response to changes in the other processes without doing any useful work. These processes are not in the waiting state, and they are running concurrently. This is different from a deadlock because in a deadlock all processes are in the waiting state.