Parallel Checker
Requires
- VS 2022 (Version 17.4.2) or higher
For previous VS 2019 support, see the separate Parallel Checker release on VS Marketplace:
https://marketplace.visualstudio.com/items?itemName=LBHSR.HSRParallelCheckerforC7VS2017
The Parallel Checker is an extension that detects data races, deadlocks and other concurrency issues in C#.
Notes
- To improve compatibility and ease installation, the Parallel Checker does no longer require full solution analysis mode activated in Visual Studio.
- Parallel Checker does no longer display diagnostic information messages on successful analysis. Only in the case of internal checker errors (e.g. implementation restrictions), the information messages are displayed.
Installation
- In VS, open Tools->Extensions and Update, search online for “Parallel Checker” and download “Parallel Checker for C# 10 (VS 2022)”.
- 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.
- To test the installation, paste the following code into “Program.cs” that contains a data race:
using System;
using System.Threading.Tasks;
class Program
{
static void Main()
{
int x = 0;
Task.Run(() => x++);
Console.Write(x);
}
}
- Open the “Error List” view. Concurrency errors detected by the parallel checker will here be listed after some delay of a few seconds.
- If checker messages are not being displayed right away, edit the code a little bit, to trigger the background analysis process in VS. Or alternatively, you may build the solution.
- Issues are also underlined in the code.
Hint: If messages are still not displayed, it may help to increase the analysis scope:
- Menu "Tools"->"Options"
- Select option page "Text Editor"->"C#"->"Advanced"
- Change "Run background code analysis for:" to "Entire solution".
- Also change "Show compiler errors and warning for:" also to "Entire solution".
Concurrency Issues
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.
Samples
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://github.com/blaeser/parallelchecker/tree/main/doc/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.
More Information
You can find more information on the checker website https://github.com/blaeser/parallelchecker