Concurrency On Windows
It seems that no matter where I go or who I talk to that multithreading, concurrency, parallelism, synchronization and asynchronous programming are just hard topics for people to understand. In general, here are my general simple guidelines that I recommend people to follow.
Taking a Lock
Think of taking a lock? Think again. Think about it some more. Think another time. Then go ask someone you know who understands locking and synchronization. You may find a way to structure your code so that it does not have to take a lock.
Parallelism vs. Asynchronous
I am all for taking advantage of hardware especially CPUs using parallelism. Keep in mind that there are different types of parallelism such as IO vs. CPU parallelism. Don’t get them confused. Also, know what frameworks you are using for parallelism. Some are designed for CPU parallelism which means that if you need IO parallelism, you might do better with not using these frameworks.
There are many times that people think that they need parallelism, but in reality they may just need asynchronous operations. This is especially true if you are doing file operations, web service calls or database calls. This usually arises from the need to not block, especially in the case of user interface interactions.
More Threads Is Not Better
Do not think that more threads is better. In fact, in almost all cases more threads is absolutely bad. A single CPU can only execute one thread at a time. To achieve multitasking a CPU must switch between threads. This switching between threads is known as context switching. The more context switching the less time is spent actually executing your code. In general, assuming that you have a N core system, the most efficient number of threads will be N.
Book Recommendations
Without a doubt the following books are some of the best books on parallelism, concurrency and multithreading for Windows. I highly recommend any of these books.
Concurrency Programming on Windows




