<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>You had me at "Hello World" : Multi Thread</title><link>http://blogs.msdn.com/helloworld/archive/tags/Multi+Thread/default.aspx</link><description>Tags: Multi Thread</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Fixing the Issue that Does Not Exist</title><link>http://blogs.msdn.com/helloworld/archive/2009/02/05/fixing-the-issue-that-does-not-exist.aspx</link><pubDate>Thu, 05 Feb 2009 14:06:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9399568</guid><dc:creator>HelloWorld</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/helloworld/comments/9399568.aspx</comments><wfw:commentRss>http://blogs.msdn.com/helloworld/commentrss.aspx?PostID=9399568</wfw:commentRss><description>&lt;p&gt;I spent some time planning on improvements that I wanted to do on one of our project. I reviewed the code that I notice a place where I think I could improve the performance by avoiding locking.&lt;/p&gt;  &lt;p&gt;So I wrote the code, and tested it, works great, the new non-locking algorithm works fine. Then when I replaced the old code with my new code and ran my test, to my surprise, it did not behave the way I want it to be. Still works, but the performance and the throughput was not any better. In some cases, it actually yield worse performance compared with the old code.&lt;/p&gt;  &lt;p&gt;Curious, I captured the performance counters by running my test app side by side, the one with old code, and the other one with new code.&lt;/p&gt;  &lt;p&gt;Look and behold, under extreme cases, the old code has zero Total # of Contentions. The new code, of course has zero Total # of Contentions, and at the same time, consumes more memory due to the lock free algorithm implementation that I chose.&lt;/p&gt;  &lt;p&gt;Basically, the lock free code tries to solve a problem that did not exist in the old code. Yes, it uses lock, but the old code runs really fast, and it is very tight, so there was no contention.&lt;/p&gt;  &lt;p&gt;Moral of the story, reviewing the code may reveal some issue, put it to test, and verify that the issue is really an issue, before planning any work on it. One good thing, I did not spend too much time on it. :)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9399568" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/helloworld/archive/tags/.Net+Framework/default.aspx">.Net Framework</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/Multi+Thread/default.aspx">Multi Thread</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/Performance/default.aspx">Performance</category></item><item><title>When Building Multi-Threaded Applications using ThreadPool, Make the Number of Worker Threads Configurable</title><link>http://blogs.msdn.com/helloworld/archive/2008/12/16/when-building-multi-threaded-applications-using-threadpool-make-the-number-of-worker-threads-configurable.aspx</link><pubDate>Tue, 16 Dec 2008 14:14:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9224423</guid><dc:creator>HelloWorld</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/helloworld/comments/9224423.aspx</comments><wfw:commentRss>http://blogs.msdn.com/helloworld/commentrss.aspx?PostID=9224423</wfw:commentRss><description>&lt;p&gt;Just a simple thought, when creating a multi-threaded applications, make the number of threads configurable. ThreadPool has this behavior that it will immediately set the minimum worker threads equal to the number of logical processors in your machine, and set the maximum to 250 per logical processor, well documented in msdn (.Net Framework 2.0 SP1).&lt;/p&gt;  &lt;p&gt;ThreadPool will create a new thread every half second, also documented in msdn. This behavior could lead to thread explosions, where there are too much threads fighting for limited resources (memory, lock, disk IO, processor, etc.). Your app may run slower if the thread creation is not managed wisely.&lt;/p&gt;  &lt;p&gt;It is also a good idea to be able to throttle the application to use fewer threads. It is a good idea to be able to limit the number of threads in the system through configuration. Set the max number of threads by calling SetMaxThreads, and if the config value is less than the number of logical processors, do not forget to call SetMinThreads. Be aware that this can also lead to other issue, like thread starvation.&lt;/p&gt;  &lt;p&gt;This is just an idea, if you have been writing multi-threaded applications using ThreadPool, probably you have thought about this already. Keep in mind, your application needs as few thread as possible, but not fewer.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9224423" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/helloworld/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/.Net+Framework/default.aspx">.Net Framework</category><category domain="http://blogs.msdn.com/helloworld/archive/tags/Multi+Thread/default.aspx">Multi Thread</category></item></channel></rss>