Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have had problems myself with delays in thread startup when using the (.Net 4.0) Task-object. So for time-critical stuff I now use dedicated threads (... again, as that is what I was doing before .Net 4.0.)</p> <p>The purpose of a thread pool is to avoid the operative system cost of starting and stopping threads. The threads are simply being reused. This is a common model found in for example internet servers. The advantage is that they can respond quicker.</p> <p>I've written many applications where I implement my own threadpool by having dedicated threads picking up tasks from a task queue. Note however that this most often required locking that can cause delays/bottlenecks. This depends on your design; are the tasks small then there would be a lot of locking and it might be faster to trade some CPU in for less locking: <a href="http://www.boyet.com/Articles/LockfreeStack.html" rel="noreferrer">http://www.boyet.com/Articles/LockfreeStack.html</a></p> <p>SmartThreadPool is a replacement/extension of the .Net thread pool. As you can see in this link it has a nice GUI to do some testing: <a href="http://www.codeproject.com/KB/threads/smartthreadpool.aspx" rel="noreferrer">http://www.codeproject.com/KB/threads/smartthreadpool.aspx</a></p> <p>In the end it depends on what you need, but for high performance I recommend implementing your own thread pool. If you experience a lot of thread idling then it could be beneficial to increase the number of threads (beyond the recommended cpucount*2). This is actually how HyperThreading works inside the CPU - using "idle" time while doing operations to do other operations.</p> <p>Note that .Net has a built-in limit of 25 threads per process (ie. for all WCF-calls you receive simultaneously). This limit is independent and overrides the ThreadPool setting. It can be increased, but it requires some magic: <a href="http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=201" rel="noreferrer">http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=201</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload