I read lots of .Net resources telling me that I should be using a thread pool thread rather than instantiating a new thread myself. They say you should do this because instantiating a new thread is an expensive operation. What happens during thread creation that makes it an expensive operation?
Share
Everything is relative. Creating a new thread is expensive… relative to not creating one. If you’re not doing a lot of work per thread, the work involved in building and tearing down the threads can potentially make up a measurable portion of your cpu time. But it’s cheap relative to creating a new process, especially on Windows.
It’s also generally better to use the threadpool because it is tuned to help you avoid having too many threads active at once. You rarely want more than a handful of threads active at one time, or you’ll spend a lot of cpu time performing context-switches between them all. Using the threadpool manages this for you, as additional requests are queued until a worker thread is ready.