1 Asynchronous programming and multithreading
This chapter covers
- What is multithreading.
- What is asynchronous programming.
- Why we should use them.
Multithreading and asynchronous programming are two ways to make the computer do more than one thing at the same time. Multithreading is about making it seem like the computer is doing multiple things (more things than the number of CPU cores) at the same time and asynchronous programming is about better utilizing the CPU in all the situations that would normally cause the CPU to wait.
Making the computer do more than one thing at the same time is extremely useful; it can help keep native apps responsive while they work, and it is required to write high performance servers that can communicate with multiple clients.
Each of those techniques is totally adequate for creating a responsive client application of server with a handful of clients – but together they can be used to take performance to the next level and have servers that can respond to thousands of clients at the same time.
Multithreading and asynchronous programming are not only immensely powerful, but also, unfortunately, unintuitive, difficult to use correctly and full of pitfalls.