Detects deadlocks occurring because of circular wait conditions.
Implements
Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
[Metric("UsedFeatures", "PostSharp.Patterns.Threading.DeadlockDetectionPolicy")]
[LinesOfCodeAvoided(0)]
[Obsolete("This aspect is deprecated and will not be maintained.", false)]
[Serializer(typeof(DeadlockDetectionPolicy.Serializer))]
public sealed class DeadlockDetectionPolicy : AssemblyLevelAspect, IAspectBuildSemantics, IValidableAnnotation, IAssemblyLevelAspect, IAssemblyLevelAspectBuildSemantics, IAspectProvider, IAspect, IService
Remarks
The DeadlockDetectionPolicy works by building, in real time, a graph
of dependencies between threads and waiting objects. All synchronization aspects of
the threading pattern library, additionally to the most common .NET synchronization primitives.
The following .NET methods that are supported:
Mutex.WaitOne
, Mutex.WaitAll
, Mutex.Release
, Mutex.SignalAndWait
,
Monitor.Enter
, Monitor.Exit
, Monitor.TryEnter
, Thread.Join
,
all methods of ReaderWriterLockSlim
, all methods of ReaderWriterLock
except
ReaderWriterLock.ReleaseLock
, ReaderWriterLock.RestoreLock
,
all methods of Dispatcher
, Dispatcher.BeginInvoke
, Dispatcher.InvokeAsync
,
DispatcherOperation.Wait
, Dispatcher
.
Calls to methods of objects that are not listed above will not be tracked and deadlocks involving them will not be detected. Similarly, if a call to these methods is made from an assembly not having this policy applied, it will not be observed and a deadlock this method call participates in will not be detected.
This policy does not support async methods. Deadlocks caused by await
will not be detected.
When synchronization objects wait for more than 200ms, a deadlock detection is performed. The algorithm analyzes the dependency graph for cycles and throws a DeadlockException in all threads involved in the cycle if one is detected.
Some actions on synchronization primitives, such as ReaderWriterLock.RestoreLock
and WaitHandle.Handle
,
make it impossible to track deadlocks. If such methods are called, the synchronization primitive is excluded from
the deadlock detection mechanism. If too many objects are excluded, the deadlock detection is automatically turned off.
Constructors
Name | Description |
---|---|
DeadlockDetectionPolicy() | |
DeadlockDetectionPolicy(PortableFormatterConstructorContext) |
Methods
Name | Description |
---|---|
CompileTimeValidate(Assembly) | Method invoked at build time to ensure that the aspect has been applied to the right target. |
IsEnabled(Assembly) | Determines whether an Assembly has been instrumented for deadlock detection. |