Customizing threads and processes safely
In this section, we will cover some of the pitfalls that we have to avoid when being creative with threads and processes. We will not cover the concepts in depth, as advanced multiprocessing and concurrency is a big topic and there are books completely dedicated to this. However, it is important to understand what to look out for and which topics to read if you want to increase your knowledge of multiprocessing/threading.
Looking back at our Fibonacci sequences, it might be tempting to spin off extra threads inside our thread to speed up the individual computations in the thread pool. However, to truly understand if this is a good idea, we need to understand Amdahl's law.
Amdahl's law
Amdahl's law lets us describe the trade-off on adding more threads. If we spin off threads inside the threads, we will have exponential growth of threads. You may be forgiven for thinking this to be a good idea; however, Amdahl's...