Training: .NET Parallel Programming
Mastering parallel and asynchronous programming with the latest Microsoft .NET and C# 7.
Two-Day Professional Training
Instructor: Luc Bläser
Parallelization 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, the .NET framework offers a wide spectrum of features for parallel and asynchronous programming.
However, parallelization also poses new and demanding problems and challenges for the software engineers:
- Under which conditions and how may the software be accelerated by threads and 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?
- Which specific parallelization pitfalls exist with the .NET framework?
- How can the .NET Task Parallel Library be optimally employed?
- What needs to be considered with the async & await programming model?
This two-day course addresses the efficient and safe usage of parallelization and concurrency with the latest .NET Framework. Throughout the course, C# 7 is used as the language for the programming examples developed in Microsoft Visual Studio 2017. The course is accompanied by practical exercises, in which the attendees can apply and deepen their gained knowledge.
The course provides an in-depth overview and detailed discussion of the concurrency concepts in .NET with focus on their safe and efficient application in practice. This course is designed to not only cover .NET standard parallelization know-how but also goes beyond the horizon of current literature. For instance, it also confronts particular risks and pitfalls with .NET multi-threading and the .NET TPL, while demonstrating various solution approaches.
This course is targeted at professional software engineers and software architects, who want to gain an expert knowledge of the parallelization and concurrency aspects within the Microsoft .NET framework. 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.
List of Contents
Introduction, system support for parallelism
- Motivation: Why parallel programming?
- Levels of parallelism
- Parallel computer architectures
- Parallelism and concurrency
- 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
- Count-down events
- Reader-writer locks
- 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 problem
- 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
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 parallelization trends