Process Threads - how do they work?

Soldato
Joined
12 May 2005
Posts
12,631
Been wanting to ask this question a while.

Ok, so at the moment, I bring up task manager. I see at Spybots "Tea Timer" and see it uses 6 threads. Media Player Classic is using 16.

How does this work? is it simp[ly that the more complex a program is (in other words, the more "parts" to it, such as actual mini tasks with in the programe, each get another thread?

Also, (not 100 percent on the wording here) but I have noticed some CPU's say they handle say 3 hardware threads. How does that work, when I have say a 100 threads (most likely more) on my PC with the processes.

I realize this is kind of a complex topic, but if someone could give a brief diescription, and possibly a link or 2 to more advanced reading, I would really appreciate it :)
 
In the Windows world a process is an abstract object - it doesn't actually exist. It is just there to provide a container for the process' actual threads. In the Unix world a process is a thread and threads don't exist.

Continuing on a Windows world theme:

All processes have at least one thread.

Almost all applications nowadays use multiple threads. But that is not to say that they use those threads to improve concurrency and therefore performance. Usually it is done to maintain a responsive GUI. For example, you open a large 100MB file in Winword... Winword schedules the processing work on a seperate thread. Meanwhile the main application thread (a.k.a the GUI thread) provides a progress bar and a "Cancel" button so the user can cancel the long operation. If Winword had opened the large file on the GUI thread then the GUI would freeze and would show up as "Not Responding" in the title bar before long. Although eventually it would come back once it has finished loading the file. If this happens often on an application it generally means it was coded by monkey's.

This is as opposed to an application which is using multiple threads to actually improve performance... for example WinZIP/WinRAR now support multi-threads to extract/compress files. So during a compression task WinRAR might open up 4 threads (if you have a quad core CPU say) and each thread is performing a compression operation for each file that is being compressed, or maybe each "block" of each file (depends how fine grained their MT implementation is). Then once each major piece of work has been completed it is assembled together by a sort of master thread and output to the hard disk. The key to these sort of implementations is the way the threads are kept in order by the managerial thread. So that work jobs don't get bundled into the generated file in the incorrect order...

I don't know of any CPU's today which support 3 hardware threads. Most support 2. For instance a P4 with Hyperthreading supports 2 hardware threads. A Core2Duo supports 2. A Core2Quad supports 4... This simply refers to how many threads the processor can deal with simultaneously. Obviously in the case of Core2 it provides almost linear gains. But a P4 w/ HT is less straight forward.
 
In the Unix world a process is a thread and threads don't exist.

Well its not that clear cut tbh. Signal handling code for example makes a distinction between threads and processes and also threads share the same address space (processes usually don't). Also on Solaris for example there is a big difference between LWP's and threads...
 
I don't know of any CPU's today which support 3 hardware threads. Most support 2. For instance a P4 with Hyperthreading supports 2 hardware threads. A Core2Duo supports 2. A Core2Quad supports 4... This simply refers to how many threads the processor can deal with simultaneously. Obviously in the case of Core2 it provides almost linear gains. But a P4 w/ HT is less straight forward.

UltraSPARC T2 is an 8-core chip where each core can handle 8 threads concurrently allowing 64 threads to be processed together. This even extends to the ability to run 64 logical domains with each one running its own instance of the OS - 64 virtual machines on the one computer without thread contention!
 
UltraSPARC T2 is an 8-core chip where each core can handle 8 threads concurrently allowing 64 threads to be processed together. This even extends to the ability to run 64 logical domains with each one running its own instance of the OS - 64 virtual machines on the one computer without thread contention!

Victoria falls UltraSPARC in a 4-Way can run 256. Crazy :)
 
Well its not that clear cut tbh. Signal handling code for example makes a distinction between threads and processes and also threads share the same address space (processes usually don't). Also on Solaris for example there is a big difference between LWP's and threads...

Agreed it isn't that clear cut but in general "BSD style Unix terms" it is a fair statement. I am also aware that there are plenty of programming libraries which add in support for threading.
 
UltraSPARC T2 is an 8-core chip where each core can handle 8 threads concurrently allowing 64 threads to be processed together. This even extends to the ability to run 64 logical domains with each one running its own instance of the OS - 64 virtual machines on the one computer without thread contention!

I was talking in the perspective of Wintel...

Yikes.. tough crowd this evening :eek::)
 
Back
Top Bottom