Threads are sequences of computation that can run independently on a CPU core, simultaneously with other such sequences. So, one of the first questions we need to ask ourselves is: how many threads should we have? Unlike tasks, which are lightweight, threads need to store some state when they are switched. Thus, while you can have hundreds or thousands of tasks in your program, you should only have a limited number of threads. The general advice is that the number of threads should correspond directly to the number of CPU cores you have.
Threads
Measuring CPU cores
So, how many CPU cores do you have? The answer might not be so easy to get to. One particular complication is hyper-threading. This is a facility that Intel CPUs have that...