Wednesday, August 01, 2012 5:15 PM
I want to use multiple threads in order to get performance (I love performance), So how should I configure the ThreadPool so it uses as many threads as it should for my cpu, so my program will be fast. I'm not afraid to take up much resource as long as it benefits the performance of the program.
thanks in advance!
Wednesday, August 01, 2012 5:33 PMModerator
The ThreadPool in .NET already scales by the number of processors in your system. You don't (normally) need to do anything to tweak it - it's already oriented towards maximizing overall throughput.
In order to get the most performance out of your program, I'd focus more on profiling and measuring, and adapting your routines as needed - not on trying to configure the ThreadPool.
That being said, if you're algorithm is pure CPU, you may want to restrict the parallelism explicitly to 1 thread per core - the ThreadPool will typically use >1 thread/core, which can cause over subscription in some cases - again, without profiling, it's impossible to know, but that can happen. The easiest way to handle this is to use the TPL and set MaxDegreesOfParallelism (or create a custom TaskScheduler).
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
- Marked As Answer by mad-YuRi Wednesday, August 01, 2012 5:37 PM
Thursday, August 02, 2012 12:20 AM
int a, b; ThreadPool.GetMaxThreads(out a, out b); ThreadPool.SetMinThreads(a, b);gives much better performance