Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Parallel Programming with C# 8 and .NET Core 3

You're reading from   Hands-On Parallel Programming with C# 8 and .NET Core 3 Build solid enterprise software using task parallelism and multithreading

Arrow left icon
Product type Paperback
Published in Dec 2019
Publisher Packt
ISBN-13 9781789132410
Length 346 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Shakti Tanwar Shakti Tanwar
Author Profile Icon Shakti Tanwar
Shakti Tanwar
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Section 1: Fundamentals of Threading, Multitasking, and Asynchrony FREE CHAPTER
2. Introduction to Parallel Programming 3. Task Parallelism 4. Implementing Data Parallelism 5. Using PLINQ 6. Section 2: Data Structures that Support Parallelism in .NET Core
7. Synchronization Primitives 8. Using Concurrent Collections 9. Improving Performance with Lazy Initialization 10. Section 3: Asynchronous Programming Using C#
11. Introduction to Asynchronous Programming 12. Async, Await, and Task-Based Asynchronous Programming Basics 13. Section 4: Debugging, Diagnostics, and Unit Testing for Async Code
14. Debugging Tasks Using Visual Studio 15. Writing Unit Test Cases for Parallel and Asynchronous Code 16. Section 5: Parallel Programming Feature Additions to .NET Core
17. IIS and Kestrel in ASP.NET Core 18. Patterns in Parallel Programming 19. Distributed Memory Management 20. Assessments 21. Other Books You May Enjoy

Moving from sequential loops to parallel loops

The TPL supports data parallelism through the System.Threading.Tasks.Parallel class, which provides parallel implementation of the For and Foreach loops. As a developer, you don't need to worry about synchronization or creating tasks as this is handled by the parallel class. This syntactic sugar allows you to easily write parallel loops in a way that's similar to how you have been writing sequential loops.

Here is an example of a sequential for loop that books a trade by posting the trade object to the server:

foreach (var trade in trades)
{
Book(trade);
}

Since the loop is sequential, the total time that it takes to finish the loop is the time it takes to book one trade multiplied by the total number of trades. This means that the loop slows down as the number of trades increases, although the trade booking time remains...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime