Using the Parallel Programming Library
Any modern CPU has a multi-core architecture. This means multiple applications can run in parallel at the same time in the foreground or the background. That’s not specifically interesting for developers. What’s relevant, though, is that a multi-core CPU allows single applications to use more than one core at the same time, spawning additional threads of execution and running them in parallel.
While this feature offers a lot of power to CPU-bound applications (applications that need to perform a lot of calculations or CPU operations), it is one of the most difficult to use as a developer. This is because multithreaded applications need to be written with a lot of care since different threads might access the same resources at the same time. Hence, threads need to synchronize any shared resource access, which is far from a simple operation in many cases.
This chapter will cover the following parts:
- Using threads ...