1 Functional concurrency foundations

 

This chapter covers

  • Why you need concurrency
  • Differences between concurrency, parallelism, and multithreading
  • Avoiding common pitfalls when writing concurrent applications
  • Sharing variables between threads
  • Using the functional paradigm to develop concurrent programs

In the past, software developers were confident that, over time, their programs would run faster than ever. This proved true over the years due to improved hardware that enabled programs to increase speed with each new generation.

For the past 50 years, the hardware industry has experienced uninterrupted improvements. Prior to 2005, the processor evolution continuously delivered faster single-core CPUs, until finally reaching the limit of CPU speed predicted by Gordon Moore. Moore, a computer scientist, predicted in 1965 that the density and speed of transistors would double every 18 months before reaching a maximum speed beyond which technology couldn’t advance. The original prediction for the increase of CPU speed presumed a speed-doubling trend for 10 years. Moore’s prediction, known as Moore’s Law, was correct—except that progress continued for almost 50 years (decades past his estimate).

Today, the single-processor CPU has nearly reached the speed of light, all the while generating an enormous amount of heat due to energy dissipation; this heat is the limiting factor to further improvements.

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.3.1 Present and future of concurrent programming

1.4 The pitfalls of concurrent programming

1.4.1 Concurrency hazards

1.4.2 The sharing of state evolution

1.4.3 A simple real-world example: parallel quicksort

1.4.4 Benchmarking in F#

1.5 Why choose functional programming for concurrency?

1.5.1 Benefits of functional programming

1.6 Embracing the functional paradigm

1.7 Why use F# and C# for functional concurrent programming?

Summary