Parallel Checker
** No longer maintained. Change to newest version for VS 2022: https://marketplace.visualstudio.com/items?itemName=LBHSR.ParallelChecker**
Requires:
- VS 2019 Version (16.9.6) or higher
- VS 2019 Preview 4.0 (16.10.0) or higher.
The Parallel Checker is an extension that detects data races, deadlocks and other concurrency issues in C#.
Notes
- The checker will automatically enable C# full solution analysis.
To disable this, go to Tools->Options->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->Parallel Checker: Set “Diagnostic Checker Information” to false. Reload the solution or restart VS.
- If checker messages are not being displayed, please activate “entire solution analysis” manually: Go to menu “Tools->Options”, navigate to “Text Editor->C#->Advanced”, and select “Entire solution” under “Background analysis scope”.
- If messages do not appear right away after opening the solution, it may help to edit the source code a little bit to trigger the background analysis process in VS.
Installation
- In VS, open Tools->Extensions and Update, search online for “Parallel Checker” and download “Parallel Checker for C# 9 (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:
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, please activate “entire solution analysis” manually: Go to menu “Tools->Options”, navigate to “Text Editor->C#->Advanced”, and select “Entire solution” under “Background analysis scope”.
- Alternatively,build the solution or edit and save the code, to trigger the background analysis process in VS.
- Issues are also underlined in the code.
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