Functional Concurrency in .NET
With examples in C# and F#
Riccardo Terrell
  • MEAP began December 2016
  • Publication in Fall 2017 (estimated)
  • ISBN 9781617292996
  • 350 pages (estimated)
  • printed in black & white

The multicore processor revolution has begun. Parallel computation is powerful and increasingly accessible and multicore computation is incorporated into all sorts of applications, including finance software, video games, web applications, machine-learning, and market analysis. To get the best performance, your application has to partition and divide processing to take full advantage of multicore processors. Functional languages help developers support concurrency by encouraging immutable data structures that can be passed between threads without having to worry about a shared state, all while avoiding side effects.

Functional Concurrency in .NET teaches you how to build concurrent and scalable programs in .NET using the functional paradigm. This intermediate-level guide is aimed at developers, architects, and passionate computer programmers who are interested in writing code with improved speed and effectiveness by adopting a declarative and pain-free programming style. You'll start by learning the foundations of concurrency and important functional techniques and paradigms used in the rest of the book. Then you'll dive in to concurrent and parallel programming designs, emphasizing the functional paradigm with both theory and practice with lots of code samples. The third part of the book covers a real "cradle to grave" application implementation, covering the techniques and skills learned during the book.

Table of Contents detailed table of contents


1. Functional Concurrency Foundations

1.1. Let’s start with terminology

1.1.1. Sequential programming

1.1.2. Concurrent programming

1.1.3. Parallelism

1.1.4. Multitasking

1.1.5. Multithreading

1.2. Why the need for concurrency?

1.2.1. Present and future of concurrent programming

1.3. The Pitfalls of Concurrent Programming

1.3.1. Concurrency hazards

1.3.2. The sharing-of-state evolution

1.3.3. A simple real-world example: parallel quicksort

1.3.4. Benchmarking in F#

1.4. Why Choose Functional Programming for Concurrency

1.4.1. Benefits of functional programming

1.5. Embracing the functional paradigm

1.6. Why use F# and C# for functional concurrent programming

1.7. Summary

2. Functional Programming Techniques for Concurrency

2.1. Function composition

2.1.1. Function composition in C#

2.1.2. Function composition in F#

2.2. Closure

2.2.1. Captured variables in closures with lambda expressions

2.2.2. Closure in a multithreading environment

2.3. Memoization-caching technique

2.3.1. Memoized web crawler

2.3.2. Lazy memoization for better performance

2.3.3. Gotchas for function memoization

2.4. Effective Concurrent Speculation

2.4.1. Precomputation with natural functional support

2.4.2. Let the best computation win

2.5. Being lazy is a good thing

2.5.1. Strict languages for better concurrency

2.5.2. Lazy caching technique and thread-safe singleton pattern

2.5.3. Lazy support in F#

2.5.4. Lazy and Task, a powerful combination

2.6. Summary

3. Functional Data Structures and Immutability

3.1. Real-world example - Hunt the thread-unsafe object

3.1.1. .NET immutable collections: a safe solution

3.1.2. The .NET concurrent collections: a faster solution

3.1.3. The Agent message passing pattern - a faster and better solution

3.2. Functional data structure (FDS)

3.3. Immutability for a change

3.3.1. Functional data structure for data parallelism

3.3.2. Performance implication

3.3.3. Immutability in C#

3.3.4. Immutability in F#

3.3.5. Functional lists

3.3.6. Building a persistent data structure - an immutable binary tree (B-Tree)

3.4. Recursive function

3.4.1. The tail of a correct recursive function - Tail-Call optimized

3.4.2. Continuation passing style (CPS)

3.5. Summary


4. The Basics of Processing Big Data : Data Parallelism Part 1

4.1. What is data parallelism

4.1.1. Data and task parallelism

4.1.2. The "embarrassingly parallel" concept

4.1.3. Data parallelism support in .NET

4.2. The Fork/Join pattern: Parallel Mandelbrot

4.2.1. The downside of parallel loops

4.3. Performance speed

4.3.1. Amdahl's Law

4.3.2. Gustafson's Law

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

4.4. Summary

5. PLINQ and Map-Reduce : Data Parallelism Part 2

6. Real-Time Event Streams : Functional Reactive Programming

7. Task-based Functional Parallelism

8. Incorporating Asynchronicity for the Win

9. Applying Reactive Programming Everywhere With Agents


10. How to Choose the Right Concurrent Model and Design

11. Sideloading tasks to a computer's GPU Processor

12. Mobile App Concerns : Reactive & Responsive UIs

13. Design Patterns for Concurrent Apps


Appendix A: Functional Programming Fundamentals

Appendix B: F# Fundamentals

What's inside

  • Code examples in both C# and F#
  • Building high-performance concurrent systems
  • Integrating concurrent programming abstractions
  • Concurrent patterns such as fork/join, producer-consumer, Map-Reduce and pipeline
  • Implementing a real-time event stream processing
  • Seamlessly accelerate sequential programs by using data-parallel collections
  • Creating a data-access layer to handle massive concurrent requests

About the reader

This book is for readers with solid knowledge of a mainstream programming language, preferably C# or F#.

About the author

Riccardo Terrell is a .NET seasoned software engineer, senior software architect and Microsoft MVP who is passionate about functional programming. He is well known and actively involved in the functional programming community including .NET meet ups and conferences and is the organizer for the Washington DC F# User Group.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $49.99 pBook + eBook
MEAP eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks