Method non-synchronized that read mutable states
Lists methods reading mutable state (modifiable instance or static fields) without synchronizing access — a potential state corruption in multi-threaded programs. Not a rule: most matches are not an issue.
CQLinq source
This code query is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.
// <Name>Method non-synchronized that read mutable states</Name>
// <Id>ND2505:MethodNonSynchronizedThatReadMutableStates</Id>
from m in Application.Methods where
(m.ReadsMutableObjectState || m.ReadsMutableTypeState) &&
!m.IsUsing ("System.Threading.Monitor".AllowNoMatch()) &&
!m.IsUsing ("System.Threading.ReaderWriterLock".AllowNoMatch())
select new {
m,
mutableFieldsUsed = m.FieldsUsed.Where(f => !f.IsImmutable)
}
//<Desc>
// Lists methods reading mutable state (modifiable instance or static
// fields) without synchronizing access — a potential state corruption in
// multi-threaded programs. Not a rule: most matches are not an issue.
//</Desc>
Open in the interactive Rules Explorer · All default rules
.NET Framework Usage / System.Threading: all 6 items
- Don't create threads explicitly ND2500
- Don't use dangerous threading methods ND2501
- Monitor TryEnter/Exit must be both called within the same method ND2502
- ReaderWriterLock AcquireLock/ReleaseLock must be both called within the same method ND2503
- Don't tag instance fields with ThreadStaticAttribute ND2504
- Method non-synchronized that read mutable states ND2505