An Ideal Number of Threads?

Based on those observations, what is an ideal number of threads? If we have too many threads competing for processor time, we face the costs of swapping back and forth between them. If we have too few, we’re underutilizing the cores we have at our service. Figure 30.1 shows how a well-tuned parallel program could go about optimizing the number of threads by having work queues associated with each processor core available.

Figure 30.1. Keeping processors busy with an ideal number of threads.

image

In fact, this is pretty close to various pooling architectures, one of which we look at in this chapter. Now a key question becomes ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.