By Kato Mivule
The Two Phase Protocol (2PL) protocol has found wide spread implementation in distributed database systems and research continues on how better to detect and prevent deadlocks in the 2PL protocol in distributed database systems. In this discussion we take a review of the 2PL protocol, definitions of terms involved to 2PL, the deadlocks, and some suggestions on how to avoid deadlocks in the 2PL Protocol.
Even though the 2PL Protocol finds wide use in distributed database systems, the 2PL Protocol is essential in operating systems and to better grasp the 2PL protocol, a look at Serializability and Locking Protocol is an important first step, as these concepts are foundational to understanding the 2PL Protocol.
Serializability is a situation where multiple transactions are active simultaneously, and each transaction is atomic, the concurrent execution of transactions have to be equivalent in order to execute the processes serial.  To ensure serializability, each data item has to be associated with a lock and that each lock follow a locking protocol that sets rules on how locks are acquired and released.  
Locking Protocols by and large align admission to mutual shared data using locks which can be turned on or off when a transaction acquires or releases the shared data.  Silberschatz et al describe the two conditions of locking protocol as follows, with each data transaction forced to ask for lock in a suitable mode on a data item Q, as per type of activity it will do:
- Shared: If a transaction Ti has acquired a shared-condition lock on a data item Qi, then Ti can read the item but cannot write Q
- Exclusive: If a transaction Ti has received an exclusive-condition lock on a data item Q, then Ti can both read and write Q.
As described by Silberschatz et al, the problem associated with locking protocol is that serializability is not guaranteed when a transaction unlocks a data item instantly after use. 
Two Phase Protocol
One protocol that is said to guarantee serializability is the Two Phase Protocol (2PL). The 2PL Protocol oversees locks by determining when transactions can acquire and release locks.  The 2PL protocol forces each transaction to make a lock or unlock request in two steps: 
- Growing Phase: A transaction may obtain locks but may not release any locks.
- Shrinking Phase: A transaction may release locks but not obtain any new lock.
The transaction first enters into the Growing Phase, makes requests for required locks, then gets into the Shrinking phase where it releases all locks and cannot make any more requests.  Transactions in 2PL Protocol should get all needed locks before getting into the unlock phase. 
While the 2PL protocol guarantees serializability, it does not ensure that deadlocks do not happen. Silberschatz et al point out that for a given set of transactions, there could be conflict-serializable schedules that cannot be obtained by using 2PL protocol. 
Also challenges arise when 2PL protocols are faced with transactions that require communication between data sets. This is becomes a challenge in distributed applications like distributed database systems. 
According to the Encyclopedia of Library and Information science, to avoid deadlocks in 2PL Protocols, distributed applications like database management systems, employ deadlock detection mechanisms by construction of transaction wait for graphs and detecting for cycles. Any cycle detected in the wait for graph is terminated by breaking the cycle in the wait for graphs. 
In distributed database systems for example, each site is required to keep and maintain a wait for graph. The nodes in the graph are the transactions requesting for or currently holding a lock. The system, then should be able to detect any cycles and terminate any deadlocks.
The Two Phase Protocol (2PL) protocol is widely implemented in distributed database systems and research continues on how better to detect, prevent deadlocks, and optimization in the 2PL protocol in distributed database systems.
 Abraham Silberschatz, Peter B. Galvin, Greg Gagne, Operating system concepts, Edition 9, illustrated, J. Wiley & Sons, 2009, ISBN 978-0-470-12872-5, Page 264-265.
 Joseph M. Hellerstein, Michael Stonebraker, James Hamilton, Architecture of a Database System, Volume 1 of Foundations and trends in databases, Now Publishers Inc, 2007, ISBN 1601980787, 9781601980786, Page 81
 Heinrich Christian Mayr, Database and expert systems applications: 12th international conference, DEXA 2001, Munich, Germany, September 3-5, 2001 : proceedings, Volume 2113 of Lecture notes in computer science, Springer, 2001, ISBN 3540425276, 9783540425274, Page 330
 Gerhard Weikum, Gottfried Vossen, Transactional information systems: theory, algorithms, and the practice of concurrency control and recovery, The Morgan Kaufmann series in data management systems, Series in Data Management Systems, Morgan Kaufmann, 2002, ISBN 1558605088, 9781558605084, Page 130
 “TWO PHASE LOCKING.” [Online]. Available: http://research.microsoft.com/en-us/people/philbe/chapter3.pdf. [Accessed: 05-Oct-2010].
 Subhash Bhalla, Databases in networked information systems: 5th international workshop, DNIS 2007, Aizu-Wakamatsu, Japan, October 17-19, 2007 : proceedings, Volume 4777 of Lecture notes in computer science, LNCS sublibrary: Information systems and applications, incl. internet/web, and HCI, Springer, 2007, ISBN 354075511X, 9783540755111, Page 206
 Allen Kent, Encyclopedia of library and information science, Volume 65, CRC Press, 1999, ISBN 0824720652, 9780824720650, Pages 107-109, 104
 Majumdar Int To Dbms, Tata McGraw-Hill, 2001, ISBN 0074622390, 9780074622391, Page 450