HSR Parallel Checker
- VS 2019 Version 16.4 (or higher).
- .NET 4.8 (or higher).
Also supports VS 2019 Preview 16.5 with new background analysis scope option.
The HSR Parallel Checker is an extension that detects data races, deadlocks and other concurrency issues in C#.
- The checker will automatically enable C# full solution analysis.
To disable this, go to Tools->Options->HSR Parallel Checker, then set “Automatic full solution analysis” to “false”. Subsequently, disable full solution analysis under the options of “Text Editor->Advanced”. Reload the solution or restart VS.
- Checker information messages (with the blue icon) are turned on by default. To deactivate them, go to Tools->Options->HSR Parallel Checker: Set “Diagnostic Checker Information” to false. Reload the solution or restart VS.
- In VS, open Tools->Extensions and Update, search online for “HSR Parallel Checker” and download “HSR Parallel Checker for C# 8 (VS 2019)”.
- Restart VS, the VSIX installer will appear, click “Install”, and the tool will be installed. It can be installed for a single or multiple IDE-instances.
- Open VS studio and open a solution with an empty C# console application project (.NET Core or .NET Framework).
- Paste the following code into “Program.cs” that contains a data race:
static void Main()
int x = 0;
Task.Run(() => x++);
- Open the “Error List” view. Concurrency errors detected by the parallel checker will here be listed after some delay of a few seconds.
- Issues are also underlined in the code.
The checker detects the following concurrency (multi-threading) issues with a static analysis, however, not necessarily all of them:
- 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.
As a first starting point, you can try the sample C# solutions to detect data races and deadlocks.
You can download the samples from https://parallel-checker.com/Samples
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. It has been designed to efficiently deal with large software projects and find as many issues with high precision as possible.
You can find more information on the checker website https://parallel-checker.com