Skip Navigation
C# (CSharp) @lemmy.ml SourceCode @lemmy.ml

Avoid multithreading traps with Roslyn: Lock object selection

cezarypiatek.github.io Avoid multithreading traps with Roslyn: Lock object selection

How to avoid thread synchronization problems caused by improperly chosen lock object

Multithreading is one of the most difficult aspects of programming and can cause a lot of headaches. The main source of problems is often improper usage of synchronization mechanisms, which can result in deadlocks or a complete lack of synchronization despite our expectations. The infamous deadlocks can be detected in runtime thanks to tools like Concurrency Visualizer, Parallel Tasks Window or with WinDBG !dlk command. However, these tools are often used only after some unexpected behavior is observed, but it would be nice to reduce the feedback loop and detect these issues in design time. I’ve decided to create a series of blog posts where I will present what I’ve recently learned about the traps related to the multithreading in C#. I will also show you my proposition of Roslyn analyzers that can possibly help to avoid those issues right at the stage of writing the code. This part is about choosing a suitable object for locking.

0
0 comments