The checker works as a plugin for the Visual Studio® integrated development environment (IDE) and detects concurrency issues in the C# program code.
The checker detects the following concurrency (multi-threading) issues with a static analysis:
- Data Races: Unsynchronized concurrent accesses to same variable or array element, involving at least a write.
- Deadlocks: Constellations in which multiple threads block each other cyclically forever.
- Thread-unsafe usage: Unsynchronized concurrent calls or accesses of application programming interfaces that are not specified to be thread safe.
The abovementioned issues are all fundamental programming bugs that can lead to program errors. These issues occur non-deterministically, possibly sporadically or very seldom. They are therefore hard to identify in tests and are not easily reproducible. For this reason, it makes sense to use a static analysis that examines various program traces, including very specific or seldom cases, as to whether they suffer from such issues.
How It Works
The checker is implemented based on the compiler framework Roslyn and analyzes the C# source code without executing the program, called static analysis. It screens as many interesting program traces as possible within defined deterministic bounds. The analysis maintains exact and complete context information for the program, where possible. Exceptions are e.g. external input/output and missing or incorrect source code parts, in which case conservative assumptions are made. The properties of the checker can be summarized as:
- Precise: Real issues are reported without false positives (no false alarms), except when making conservative assumptions.
- Incomplete: The checker may miss potential issues (possible false negatives) as there exists no precise and complete analysis.
- Deterministic: The same issues are repeatedly reported for the same program.
The checker engages a new algorithm that has been submitted as a patent. It has been designed to efficiently deal with large software projects and find as many issues with high precision as possible.
The checker is currently in beta stage and supports the following .NET programming concepts and C# language features:
- .NET threads, Task Parallel Library, Async/Await, Parallel Invoke/For/ForEach
- Exact information about objects (aliases, shapes), array indexes etc.
- DLLs, WPF, WinForm, unit test libraries, console applications
- Solution-wide analysis
- C# 6 and C# 7 language
- All standard synchronization primitives, incl. monitor
- Memory barriers, atomic / Interlocked, volatile
- Collection API analysis
- Finalizer-related concurrency
Certain limitations apply, please see the download section for more details.
The following screenshot shows a detected data race issue for a C# code in Visual Studio: The two methods
Withdraw() are concurrently invoked on the same instance of
BankAccount. The checker has verified that there indeed exist multiple threads that concurrently call
Withdraw() on the same instance. There is no mutual lock exclusion between these two method executions, as only
Withdraw() establishes a monitor lock on
_sync. Thus, unsynchronized concurrent read/write, write/read and write/write accesses are effected by the corresponding method bodies.
More examples are contained in the samples section.
Notice: Microsoft, Visual Studio, and Visual Basic are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
All trademarks, trade names etc. are the property of their respective owners.
HSR, HSR Parallel Checker, and the contributors DO NOT have any affiliation with any mentioned trademark holders.