DDDebug is helpful finding deadlocks between threads at application run time utilizing the Thread Wait Chain Traversal (WCT) API introduced in Windows Vista. Several classes do encapsulate the Windows API in a Delphi like manner, making the usage straightforward and painless.
The most common scenario does not need more than a couple of lines of code as well as the implementation of an event handler as shown within this code snippet:
LNotifier := TWaitChainNotifier.Create(DeadlockDetected); LNotifier.CheckInterval := 500; LNotifier.Active := True procedure TSomeClass.DeadlockDetected(Sender: TObject; AThreads: TDDDThreadInfoArray; var AAbortThreads, ATryTerminate: Boolean); begin // end;
The above snippet spawns a thread which periodically checks whether any deadlocks between the threads within the process do exist. As soon as any deadlock will be detected the event OnDeadlockDetected will be invoked, passing it an array of TDDDThreadInfos of those threads involved into the deadlock.