开发者

Set the maximum number of threads in the Threadpool less than cores

开发者 https://www.devze.com 2023-02-17 10:40 出处:网络
\"You cannot set the number of worker threads or the number of I/O completion threads to a number smaller than the number of processors in the computer.\" (Threadp开发者_如何学编程ool.SetMaxThreads)

"You cannot set the number of worker threads or the number of I/O completion threads to a number smaller than the number of processors in the computer." (Threadp开发者_如何学编程ool.SetMaxThreads)

What if I need to have less threads (I'm using a resource which does not support more than 4 threads from one process)? is there a way to set the maximum to 4 for an 8 core box? I'm using Tasks in C#.


it seems you should try to limit the number of threads with access to that resource rather than the total number of threads this could be done by locking or tickets


Yes, Microsoft has such requirement that number of thread cannot be smaller than the number of processors. More info here.

I am interested to know why does Microsoft have such requirement? It should be harmless isn't it ? This requirement does not make sense...


just tried this out, and this "requirement" seems to be incorrect. i believe that it merely sets MinThreads to the # of cores in your machine by default. if i do this:

ThreadPool.SetMinThreads(1, 1);
ThreadPool.SetMaxThreads(2,2);

on a QuadCore machine, it seems to throttle the thread execution properly, if i leave out the SetMinThreads call though, it ignores my call to SetMaxThreads (since you cant set MaxThreads to less than MinThreads (which is # of cores by default))

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号