O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cutting Costs

The best way to think about threads is as virtual processors. They provide a level of abstraction on top of physical processors, and it’s the operating system’s task to switch between different threads such that all of them can make progress. The mechanism by which a thread is swapped out for another one to run is known as a context switch.

Context switches are expensive, and so is thread creation. So why would one create a plethora of threads as a means to run things in parallel? This question was exactly the motivation for introducing pools of threads. This way, the number of threads can be limited, reducing context switching. Pooling also allows for reuse of threads to carry out different work items drawn from a work item queue. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required