Book description
Concurrency in .NET teaches you to write code that delivers the speed you need for performance-sensitive applications. Featuring examples in both C# and F#, this book guides you through concurrent and parallel designs that emphasize functional programming in theory and practice. You’ll start with the foundations of concurrency and master essential techniques and design practices to optimize code running on modern multiprocessor systems.
Table of contents
- Cover
- Titlepage
- Dedication
- preface
- Acknowledgments
- About This Book
- About the Author
- About the Cover Illustration
-
Part 1 : Benefits of functional programming applicable to concurrent programs
-
Chapter 1: Functional concurrency foundations
- 1.1 What you’ll learn from this book
-
1.2 Let’s start with terminology
- 1.2.1 Sequential programming performs one task at a time
- 1.2.2 Concurrent programming runs multiple tasks at the same time
- 1.2.3 Parallel programming executes multiples tasks simultaneously
- 1.2.4 Multitasking performs multiple tasks concurrently over time
- 1.2.5 Multithreading for performance improvement
- 1.3 Why the need for concurrency?
- 1.4 The pitfalls of concurrent programming
- 1.5 Why choose functional programming for concurrency?
- 1.6 Embracing the functional paradigm
- 1.7 Why use F# and C# for functional concurrent programming?
- Summary
-
Chapter 2: Functional programming techniques for concurrency
- 2.1 Using function composition to solve complex problems
- 2.2 Closures to simplify functional thinking
- 2.3 Memoization-caching technique for program speedup
- 2.4 Memoize in action for a fast web crawler
- 2.5 Lazy memoization for better performance
- 2.6 Effective concurrent speculation to amortize the cost of expensive computations
- 2.7 Being lazy is a good thing
- Summary
- Chapter 3: Functional data structures and immutability
-
Chapter 1: Functional concurrency foundations
-
Part 2: How to approach the different parts of a concurrent program
-
Chapter 4: The basics of processing big data: data parallelism, part 1
- 4.1 What is data parallelism?
- 4.2 The Fork/Join pattern: parallel Mandelbrot
-
4.3 Measuring performance speed
- 4.3.1 Amdahl’s Law defines the limit of performance improvement
- 4.3.2 Gustafson’s Law: a step further to measure performance improvement
- 4.3.3 The limitations of parallel loops: the sum of prime numbers
- 4.3.4 What can possibly go wrong with a simple loop?
- 4.3.5 The declarative parallel programming model
- Summary
- Chapter 5: PLINQ and MapReduce: data parallelism, part 2
- Chapter 6: Real-time event streams: functional reactive programming
- Chapter 7: Task-based functional parallelism
-
Chapter 8: Task asynchronicity for the win
- 8.1 The Asynchronous Programming Model (APM)
- 8.2 Unbounded parallelism with asynchronous programming
- 8.3 Asynchronous support in .NET
- 8.4 C# Task-based Asynchronous Programming
-
8.5 Task-based Asynchronous Programming: a case study
- 8.5.1 Asynchronous cancellation
- 8.5.2 Task-based asynchronous composition with the monadic Bind operator
- 8.5.3 Deferring asynchronous computation enables composition
- 8.5.4 Retry if something goes wrong
- 8.5.5 Handling errors in asynchronous operations
- 8.5.6 Asynchronous parallel processing of the historical stock market
- 8.5.7 Asynchronous stock market parallel processing as tasks complete
- Summary
-
Chapter 9: Asynchronous functional programming in F#
- 9.1 Asynchronous functional aspects
- 9.2 What’s the F# asynchronous workflow?
-
9.3 Asynchronous computation expressions
- 9.3.1 Difference between computation expressions and monads
- 9.3.2 AsyncRetry: building your own computation expression
- 9.3.3 Extending the asynchronous workflow
- 9.3.4 Mapping asynchronous operation: the Async.map functor
- 9.3.5 Parallelize asynchronous workflows: Async.Parallel
- 9.3.6 Asynchronous workflow cancellation support
- 9.3.7 Taming parallel asynchronous operations
- Summary
-
Chapter 10: Functional combinators for fluent concurrent programming
-
10.1 The execution flow isn’t always on the happy path: error handling
- 10.1.1 The problem of error handling in imperative programming
- 10.2.1 Error handling in FP: exceptions for flow control
- 10.2.2 Handling errors with Task<Option<T>> in C#
- 10.2.3 The F# AsyncOption type: combining Async and Option
- 10.2.4 Idiomatic F# functional asynchronous error handling
- 10.2.5 Preserving the exception semantic with the Result type
- 10.3 Taming exceptions in asynchronous operations
- 10.4 Abstracting operations with functional combinators
- 10.5 Functional combinators in a nutshell
-
10.6 The ultimate parallel composition applicative functor
- 10.6.1 Extending the F# async workflow with applicative functor operators
- 10.6.2 Applicative functor semantics in F# with infix operators
- 10.6.3 Exploiting heterogeneous parallel computation with applicative functors
- 10.6.4 Composing and executing heterogeneous parallel computations
- 10.6.5 Controlling flow with conditional asynchronous combinators
- 10.6.6 Asynchronous combinators in action
- Summary
-
10.1 The execution flow isn’t always on the happy path: error handling
-
Chapter 11: Applying reactive programming everywhere with agents
- 11.1 What’s reactive programming, and how is it useful?
- 11.2 The asynchronous message-passing programming model
- 11.3 What is an agent?
- 11.4 The F# agent: MailboxProcessor
-
11.5 Avoiding database bottlenecks with F# MailboxProcessor
- 11.5.1 The MailboxProcessor message type: discriminated unions
- 11.5.2 MailboxProcessor two-way communication
- 11.5.3 Consuming the AgentSQL from C#
- 11.5.4 Parallelizing the workflow with group coordination of agents
- 11.5.5 How to handle errors with F# MailboxProcessor
- 11.5.6 Stopping MailboxProcessor agents—CancellationToken
- 11.5.7 Distributing the work with MailboxProcessor
- 11.5.8 Caching operations with an agent
- 11.5.9 Reporting results from a MailboxProcessor
- 11.5.10 Using the thread pool to report events from MailboxProcessor
- 11.6 F# MailboxProcessor: 10,000 agents for a game of life
- Summary
- Chapter 12: Parallel workflow and agent programming with TPL Dataflow
-
Chapter 4: The basics of processing big data: data parallelism, part 1
-
Part 3: Modern patterns of concurrent programming applied
-
Chapter 13: Recipes and design patterns for successful concurrent programming
- 13.1 Recycling objects to reduce memory consumption
- 13.2 Custom parallel Fork/Join operator
- 13.3 Parallelizing tasks with dependencies: designing code to optimize performance
- 13.4 Gate for coordinating concurrent I/O operations sharing resources: one write, multiple reads
- 13.5 Thread-safe random number generator
- 13.6 Polymorphic event aggregator
- 13.7 Custom Rx scheduler to control the degree of parallelism
- 13.8 Concurrent reactive scalable client/server
- 13.9 Reusable custom high-performing parallel filter‑map operator
- 13.10 Non-blocking synchronous message-passing model
- 13.11 Coordinating concurrent jobs using the agent programming model
- 13.12 Composing monadic functions
- Summary
-
Chapter 14: Building a scalable mobile app with concurrent functional programming
- 14.1 Functional programming on the server in the real world
- 14.2 How to design a successful performant application
- 14.3 Choosing the right concurrent programming model
- 14.4 Real-time trading: stock market high-level architecture
- 14.5 Essential elements for the stock market application
- 14.6 Let’s code the stock market trading application
- Summary
-
Chapter 13: Recipes and design patterns for successful concurrent programming
- Appendix A: Functional programming
-
Appendix B: F# overview
- The let binding
- Understanding function signatures in F#
- Creating mutable types: mutable and ref
- Functions as first-class types
- Composition: pipe and composition operators
- Delegates
- Comments
- Open statements
- Basic data types
- Special string definition
- Tuple
- Record types
- Discriminated unions
- Pattern matching
- Active patterns
- Collections
- Arrays
- Sequences (seq)
- Lists
- Sets
- Maps
- Loops
- Classes and inheritance
- Abstract classes and inheritance
- Interfaces
- Object expressions
- Casting
- Units of measure
- Event module API reference
- Appendix C: Interoperability between an F# asynchronous workflow and .NET Task
- Index
Product information
- Title: Concurrency in .NET
- Author(s):
- Release date: July 2018
- Publisher(s): Manning Publications
- ISBN: 9781617292996
You might also like
book
Tidy First?
Messy code is a nuisance. "Tidying" code, to make it more readable, requires breaking it up …
book
Hacker’s Delight, Second Edition
In Hank Warren once again compiles an irresistible collection of programming hacks: timesaving techniques, algorithms, and …
book
The Joy of JavaScript
The Joy of JavaScript introduces techniques that turn JavaScript programmers into JavaScript pros. You’ll work with …
book
Code like a Pro in C#
Code Like a Pro in C# teaches you to how write clean C# code that’s suitable …