OST Concurrency Lab

Prof. Dr. Luc Bläser

Training: .NET Parallel Programming

Mastering parallel and asynchronous programming with the latest Microsoft .NET Core and C# 9 using Visual Studio 2019 Preview.

Two-Day Professional Training

Instructor: Luc Bläser

Introduction

Parallelization, asynchrony, and concurrency gains increasing importance in software systems, be it for boosting performance with multi-cores or for enabling sophisticated non-blocking behavior. For this reason, .NET offers a wide spectrum of features for parallel, asynchronous, and concurrent programming.

Course title slide

However, parallelization, asynchrony, and concurrency also poses new and demanding problems and challenges for the software engineers:

  • Under which conditions and how may the software be accelerated by thread pools?
  • How can the dangers of race conditions, deadlocks, and starvation be systematically prevented?
  • Which software architectures, design patterns, and programming models are suited for parallelization and asynchrony?
  • Which specific parallelization and concurrency pitfalls exist within .NET?
  • How can the .NET Task Parallel Library be optimally employed?
  • What needs to be considered with the C# async & await programming model?

Topic

This two-day course addresses the efficient and safe usage of parallelization, asynchrony, and concurrency with the latest .NET versions. Throughout the course, the latest C# is used as the language for the programming examples developed in latest Microsoft Visual Studio 2019 Preview. The course is accompanied by practical exercises, in which the attendees can apply and deepen their gained knowledge.

Benefit

The course provides an in-depth overview and detailed discussion of the concurrency, asynchrony, and parallelization concepts in .NET with focus on their safe and efficient application in practice. This course is designed to not only cover .NET standard parallelization and concurrency know-how but also goes beyond the horizon of current literature and documentation. For instance, it also confronts particular risks and pitfalls with .NET multi-threading, the .NET TPL, and the C# async & await model, while demonstrating various solution approaches.

Recommended Prerequisites

This course is targeted at professional software engineers and software architects, who want to gain an expert knowledge of the parallelization, asynchrony, and concurrency aspects within Microsoft .NET. It may also be beneficial for software project leaders and technical IT managers, who would like to get a detailed overview of the possibilities and challenges with .NET parallelization and concurrency.

List of Contents

Course day 1 Course day 2
  • Introduction, system support for parallelism
    • Motivation: Why parallel programming?
    • Levels of parallelism
    • Parallel computer architectures
    • Parallelism versus concurrency versus asynchrony
    • Processes versus threads
    • Scheduling and context switches
  • Threads in .NET
    • Thread implementation, creation, and start
    • Thread exception model
    • Thread join, termination, and passivation
    • Thread lifecycle
  • Critical sections and synchronization in .NET
    • Access to shared resources
    • Critical sections
    • Synchronization with locks
    • Thread safety
    • Concurrent collections
  • Monitors in .NET
    • Monitor concept and .NET implementation
    • Monitor lock, wait and pulse, multi-pulse
    • Typical pitfalls and best practices
    • .NET monitor specifics
  • Specific synchronization primitives in .NET
    • Barriers
    • Count-down events
    • Semaphores (slim vs. standard version)
    • Mutexes
    • Reader-writer locks (incl. slim version)
    • Manual and auto reset events
  • Dangers of concurrency: races, deadlocks, starvation
    • Data races and race conditions
    • Concurrency of finalizers and timers
    • Race condition prevention
    • Deadlocks: error, detection and prevention
    • Architectural deadlock prevention
    • Starvation: error and preventions
    • Thread priority inversion and prevention
    • Concurrency correctness criteria
  • Thread pools and task parallelism with TPL in .NET
    • Thread pool concept, benefits, and limitations
    • .NET Task Parallel Library (TPL)
    • Task implementation, start and wait, result access
    • Nested tasks
    • Task chaining
    • Task exception model
    • Work-stealing thread pool mechanism
    • Task parallelism: typical pitfalls
    • Visual Studio parallel diagnostic tools
  • Data parallelism with TPL in .NET
    • Parallel invoke and parallel loops
    • Loop partitioning, efficient aggregation, stop and break
    • Performance tuning for data parallelism
    • Parallel language-integrated querying (PLINQ)
  • Asynchronous programming in .NET
    • C# async/await mechanism
    • Look behind the scenes
    • Typical pitfalls with async/await
    • Best practices and recommendations
    • New async features, such as async enumerables (await foreach), await using, async dispose etc.
  • UI and multi-threading in .NET
    • UI threading model
    • Dispatching events on UI thread
    • Non-blocking UI with async/await
    • Typical UI concurrency pitfalls in .NET
  • .NET memory model
    • Atomicity und ordering guarantees
    • Atomic instructions, Interlocked class
    • Memory barriers/fences
    • Volatile keyword
    • Fast lazy creation
    • Spin locks and spin wait hints
  • Summary and outlook
    • Lessons learned
    • Future trends in parallelization and concurrency
    • Conclusions

Other Customized Training

We also offer courses and workshops that are customized to the specific needs of the participants. Examples of some of our courses are:

  • Parallel Code Smells for .NET C# or Java
  • .NET C# 9 Upgrade
  • Parallel Programming in Java 15, incl. Stream API and Completable Futures

Please contact us for further information.