Monday, February 2, 2009

Do Threads run concurrently ?


I saw this sweet little query on my earlierpost related to  Processes and Threads.
 
Thanks for the query :-). My Apologies for not making use of the reply option..I couldn't attach the screen shot I wanted. So I am here.. With a new entry :-)

"At the operating system level there could be many concurrent threads, however at the processor execution level it is dependent on your architecture. HYPER THREADED ??   MULTI CORE ??? MULTI CORE HYPER THREADED ??"

Let me try to explain this a bit.

First thing I did  after reading the query was to hit Ctrl + Shift + Esc to bring the Task Manager Up. I want a small screen shot for the purpose..

The Snipper tool in Vista is cool.. Sitting on my XP System I really miss that.  ( snipper tool make the process of taking the screen shot much easy.... No more Alt + Print Screen.. mspaint  and stuffs..  Try it.. there is a high chance that you will like it.)


                                                             

Referring to the above Task Manager entry, I should say Current Thread count is 787.

Now.. If my understanding is correct, not all of them are in "Running" state. The other possible states for  thread are :

Aborted
AbortRequested
Background
Stopped
StopRequested
Suspended
SuspendRequested
Unstarted
WaitSleepJoin

Ref : msdn.microsoft.com/en-us/library/system.threading.threadstate(VS.80).aspx


 
At the hardware level, It is your processor who is performs all the execution for you. Refer to my earlier post on Multi Core CPU's,  If the processor is DUAL CORE  it will run two threads concurrently. If it QUAD CORE, the number will be 4.

How do we account for the mismatch then ?

                                             787 - (some suspended/ currently not running threads )  is not 2 any way ( I have a dual core system ).

This is where the scheduler comes in to picture.. All threads are time shared.. and most of them appears to be running concurrently...  Scheduler makes sure that all the threads get attention from Processor based on the assigned priority..


More on scheduling soon !!!!

BTW,  a query to theone how posted this query..Do we know each other  :-)


 

No comments:

Post a Comment