Wednesday, March 10, 2010

Interesting Questions - Expert Answers Part 3

This is the question i posed to Jeffery Ritcher on 6th March 2010

Question ( Gopala ) :
As per your words i got to know that, when  CLR intializes the threadpool gets initialized with  zero threads ..Also, the the threads are created and used but they are not destroyed instead retained in the threadpool for later use.
But in some articles( For ex : In " C# Threading handbook" by Tobil Titus) i have found out that CLR Intializes the theadpool with 25 ( defalut, and we can change this value) threads
To Verify this i tried the following code on VS2010 ( .NET 4.0)

int workerThreads1, completionPortThreads1; int workerThreads2, completionPortThreads2; int workerThreads3, completionPortThreads3;

ThreadPool.GetAvailableThreads(out workerThreads1, out completionPortThreads1);
 //workerThreads1 = 1023 completionPortThreads1 = 1000

ThreadPool.GetMaxThreads(out workerThreads2, out completionPortThreads2);
// workerThreads2 = 1023 completionPortThreads2 = 1000

ThreadPool.GetMinThreads(out workerThreads3, out completionPortThreads3);
//workerThreads3 = 2 completionPortThreads3 = 2

The results seems to be contradictary.Please Advise.

Answer ( Jeffery Ritcher) :
 
Initially the thread pool has 0 threads in it.
However, the number of worker threads in the pool can grow to 25 per CPU (by default). 25 was the number for earlier versions of the CLR.
In .NET 4.0 the default is 1023 worker threads (instead of 25) and 1000 I/O threads.
The CLR doesn’t like to create threads but, if there are work items queued up, it will quickly create up to min threads (2) and then it will slowly create more threads up to the max threads (1023).
GetAvailableThreads returns the number of threads that the thread pool could use for doing work if work gets queued up. This number changes all the time. This number does not include thread pool threads are currently doing work but these threads could return and more thread pool threads could initate doing work and this is why the number changes all the time.

Saturday, March 6, 2010

Microsoft patent on " The idea of zero"

This  is an interesting patent filed by Microsoft :
 "“an operator that returns true when two memory addresses are not equal”!
Have a look at it @

http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PG01&p=1&u=%2Fnetahtml%2FPTO%2Fsrchnum.html&r=1&f=G&l=50&s1=%2220040230959%22.PGNR.&OS=DN/20040230959&RS=DN/20040230959

Also, have a look at the "INTELLIGENT CONTAINER INDEX AND SEARCH" patent filed by microsoft 3 days back @

http://appft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%2Fnetahtml%2FPTO%2Fsearch-adv.html&r=120&f=G&l=50&d=PG01&s1=microsoft&p=3&OS=microsoft+search&RS=microsoft