microsoft / microsoft/vs-threading
Analyzer to suggest using ReentrantSemaphore instead of task chaining
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1k
- Forks
- 160
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 28
Description
Is your feature request related to a problem? Please describe.
People regularly use task chaining to accomplish a serialized, in-order execution of arbitrary operations. For example:
class Foo {
Task lastTask = Task.CompletedTask;
Task AddOperation(Action action) {
return lastTask = lastTask.ContinueWith(_ => action);
}
}
This trivial example doesn't support Func<Task> functions, and doing so properly is tricky. Avoiding deadlocks in this pattern is particularly tricky as it must be made compliant with the 3rd threading rule.
Describe the solution you'd like
An analyzer that detects when continuations of a Task field is assigned back to the original field and reports a diagnostic (warning or info) suggesting that ReentrantSemaphore be used instead.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the task-chaining example in issue #306 and review how ReentrantSemaphore is intended to replace serialized continuations. No file or test is named, so locate the existing analyzer entry points first; the work is done when the analyzer detects continuations of a Task field assigned back to that field and reports a suggestion to use ReentrantSemaphore.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100