Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 814 Bytes

PH_P012.md

File metadata and controls

21 lines (14 loc) · 814 Bytes

PH_P012 - Prefer Slim Synchronization

Problem

.NET includes synchronization types based on OS-level primitives, such as System.Threading.Semaphore. Unless inter-process synchronization is necessary, they introduce unnecessary overhead. Furthermore, they do not provide an asynchronous API.

Solution

Replace the synchronization object with a suitable Slim counterpart, for example:

  • System.Threading.Semaphore => System.Threading.SemaphoreSlim
  • System.Threading.Mutex => System.Threading.SemaphoreSlim
  • System.Threading.ReaderWriterLock => System.Threading.ReaderWriterLockSlim
  • System.Threading.ManualResetEvent => System.Threading.ManualResetEventSlim

Options

# Named synchronization primitives: ignore (default) / report
dotnet_diagnostic.PH_P012.named = ignore