Let

and

be two communicating finite state machines which exchange one type of message. We develope a polynomial algorithm to detect whether or not

and

can reach a deadlock. The time complexity of the algorithm is

and its space is

where

and

are the numbers of states in

and

, respectively. The algorithm can also be used to verify that two communicating machines which exchange many types of messages are deadlock-free.