وبلاگ بلیان

Parallel Programming with C# And . NET: Fundamentals of Concurrency and Asynchrony Behind Fast-Paced Applications

معرفی کتاب «Parallel Programming with C# And . NET: Fundamentals of Concurrency and Asynchrony Behind Fast-Paced Applications» نوشتهٔ Vaskaran Sarcar، منتشرشده توسط نشر Apress L. P. در سال 2024. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

If you need to understand concurrency, this book is your guide to the fundamentals behind the advanced software you seek to implement to achieve highly responsive and scalable code. Support for parallel computation is an essential part of concurrency. Concurrency is an advanced concept and solutions are not straightforward. Many developers have been burned by it and are still being burned by it. This book aims to simplify the concept for C# developers. It tries to simplify the concept using the Task Parallel Library (TPL), Concurrent Collections, Parallel LINQ (PLINQ), Asynchronous Programming Patterns, and related topics. The book starts with an overview of TPL and discusses Tasks. Understanding these areas is necessary to learn the concepts that follow in the book. You will go through special scenarios, such as handling exceptions and cancellations, followed by demonstrations of synchronization techniques and concurrent collections. You will see demonstrations of parallel loops to speed up the computations. And you'll understand PLINQ in detail. Finally, you'll learn how to simplify asynchronous programming with async and await keywords is discussed. The book contains “Q&A sessions”, review questions, and exercises (in .NET 8 and C#12). After reading the book, you will be able to understand advanced concepts in parallel programming and implement them in your code. What You Will Learn Understand concurrent and multi-threaded development Understand how some modern-day C# features can promote parallel programming Demonstrate the latest patterns for parallel development Who This Book Is For Developers familiar with C# but are absolute beginners for parallel programming. Table of Contents About the Author About the Technical Reviewer Acknowledgments Foreword Introduction Chapter 1: Understanding Tasks Stepping into Parallel Development Introduction to the Task Parallel Library How Does the TPL Help? The Concept of Tasks Creating and Executing a Task The Alternative Approaches Demonstration 1 Output Q&A Session Passing and Returning Values Passing Values into Tasks Returning Values from Tasks Demonstration 2 Output Q&A Session Continuation Tasks Simple Continuation Demonstration 3 Output Specialized Continuation Case Study 1 Demonstration 4 Output Analysis Q&A Session Case Study 2 Demonstration 5 Output Nested Tasks Using TaskCreationOptions Demonstration 6 Output Q&A Session Using TaskContinuationOptions Demonstration 7 Output Analysis Q&A Session Demonstration 8 Output Discussion of Waiting Why Do We Wait? Demonstration 9 Output Analysis How Do We Wait? Using Sleep Using Delay Using ReadKey() Using Wait Using WaitAll Using WaitAny Using WhenAny Waiting for Cancellation Q&A Session Exercises Summary Solutions to Exercises E1.1 E1.2 E1.3 E1.4 E1.5 E1.6 Additional Note E1.7 E1.8 Chapter 2: Handling Special Scenarios Introduction to Exceptions Understanding the Challenge Demonstration 1 Output Demonstration 2 Output Retrieving the Error Details Demonstration 3 Output Q&A Session Consider Using AggregateException Exception Management Handling Exceptions in a Single Location Demonstration 4 Output Alternative Approaches Alternative Approach 1 Alternative Approach 2 Q&A Session Demonstration 5 Output Handling Exceptions in Multiple Locations Demonstration 6 Output Final Suggestion Understanding Cancellations Different Ways of Cancellation Initial Approach Demonstration 7 Output Q&A Session Alternative Approach Demonstration 8 Output Shortening the Code Q&A Session One Final Note Q&A Session Monitoring Task Cancellation Using Register Using WaitHandle.WaitOne Demonstration 9 Output Cancelling Child Tasks Q&A Session Managing Multiple Cancellation Tokens Demonstration 10 Output Microsoft’s Note for Visual Studio Users Organizing Exceptions and Cancellations Case Study 1: Using Wait() Demonstration 11 Output Case Study 2: Using Wait(token) Q&A Session Handling I/O-Bound Tasks Using TaskCompletionSource Demonstration 12 Output Q&A Session Exercises Summary Solutions to Exercises E2.1 E2.2 E2.3 E2.4 E2.5 E2.6 E2.7 E2.8 E2.9 E2.10 E2.11 E2.12 E2.13 Chapter 3: Exploring Synchronization and Concurrent Collections Synchronization Understanding Why We Need Synchronization An Erroneous Program Demonstration 1 Output Analysis Q&A Session Using Lock Statements Demonstration 2 Output Using Interlocked Classes Demonstration 3 Output Q&A Session Signaling Using AutoResetEvent Demonstration 4 Output Analysis Q&A Session Concurrent Collections System.Collections.Concurrent Namespace IProducerConsumerCollection Interface Notable Characteristics Q&A Session ConcurrentStack Demonstration 5 Output Analysis ConcurrentQueue Demonstration 6 Output Analysis ConcurrentBag Demonstration 7 Output Analysis Q&A Session BlockingCollection Demonstration 8 Output Analysis Note from Microsoft ConcurrentDictionary Are Atomicity and Thread-Safety Guaranteed? Demonstration 9 Output Analysis Q&A Session Exercises Summary Solutions to Exercises E3.1 E3.2 E3.3 E3.4 E3.5 E3.6 E3.7 Chapter 4: Working on Parallel Loops Revisiting Sequential Loops Experimenting with Parallel Loops Introducing the Parallel Class Parallel.ForEach Parallel.For Demonstration 1 Output Analysis Parallel.Invoke Demonstration 2 Output Q&A Session Scenarios for Parallel Execution Case Study 1 Demonstration 3 Output Case Study 2 Analysis Useful Parameters Using ParallelLoopState Using Stop Demonstration 4 Output Using Break Q&A Session Retrieving More Information Using ParallelOptions Demonstration 5 Output Analysis Managing Cancellations Following the Previous Approach Recommended Approach Demonstration 6 Output Q&A Session Handling Exceptions Demonstration 7 Output Fine-Tuning Using Thread-Local Variables Demonstration 8 Output Using Partition-Local Variables Additional Note Q&A Session Reviewing Different Coding Styles Introducing the ParallelEnumerable Class Exercises Summary Solutions to Exercises E4.1 E4.2 E4.3 E4.4 E4.5 E4.6 Chapter 5: Parallel LINQ Prerequisite Knowledge Imperative vs. Declarative Programming PLINQ Supports Declarative Programming Understanding LINQ Is Beneficial The Path Toward Parallelism Converting LINQ into PLINQ Using AsParallel Using the ParallelEnumerable Class Introducing ForAll Q&A Session Getting Familiar with PLINQ The First Program Demonstration 1 Output Analysis Q&A Session Do Parallel Queries Run Faster Than Sequential Queries? Demonstration 2 Output Analysis Q&A Session Demonstration 3 Output Enabling Parallelization Output Analysis Q&A Session Forcing Parallelism and Controlling the Degree Demonstration 4 Output Merging Data Merge Options Demonstration 5 Output Suggestions Q&A Session Managing Special Scenarios Handling Exceptions Demonstration 6 Output Handling Cancellations Demonstration 7 Output Q&A Session Exercising Aggregation Sequential Custom Aggregation Parallel Custom Aggregation Demonstration 8 Output Analysis Q&A Session Exercises Summary Solutions to Exercises E5.1 E5.2 E5.3 E5.4 E5.5 E5.6 Chapter 6: Simplifying Asynchronous Programming Introduction to async and await Understanding async Naming Convention Return Types and Parameters Async Restrictions Q&A Session Understanding await Demonstration 1 Output Analysis Q&A Session Await Restrictions Q&A Session State Machines Are Behind the Scenes Q&A Session Task.Run vs. Task.Factory.StartNew Task.Factory.StartNew Treats Ordinary Lambdas and Asynchronous Lambdas Differently Task.Run Treats Ordinary Lambdas and Asynchronous Lambdas Uniformly Unwrapping Using the Unwrap Method Unwrapping Using await Asynchronous Construction Approach 1 Demonstration 2 Output Analysis Approach 2 Demonstration 3 Output Analysis Approach 3 (Using a Static Method aka Factory) Demonstration 4 Output Analysis Q&A Session Approach 4 (Lazy Initialization) Understanding Lazy Demonstration 5 Analysis Using Lazy for Async Construction Demonstration 6 Output Using Nito.AsyncEx Library Introducing ValueTasks Consuming ValueTasks Q&A Session Reviewing Exceptions Exercises Summary Solutions to Exercises E6.1 E6.2 E6.3 E6.4 E6.5 E6.6 E6.7 E6.8 E6.9 E6.10 E6.11 E6.12 Appendix A: Supplementary Notes PFX Overview Data Structures PFX Components How Does PFX Help? Partitioning Strategies Q&A Session More on Synchronization Constructs Signaling Using ManualResetEvent Demonstration 1 Output Analysis Q&A Session Signaling Using ManualResetEventSlim Demonstration 2 Output Q&A Session Signaling Using CountdownEvent Demonstration 3 Output Additional Note Using Mutex Demonstration 4 Output Additional Note Q&A Session Using SemaphoreSlim Demonstration 5 Output Q&A Session Avoiding Deadlocks More on Async/Await Task-Based Asynchronous Patterns Case Study Demonstration 6 Output Q&A Session What’s Next? A Personal Appeal Appendix B: Recommended Reading Books Courses Other Resources Appendix C: Other Books by the Author Index
دانلود کتاب Parallel Programming with C# And . NET: Fundamentals of Concurrency and Asynchrony Behind Fast-Paced Applications