views:

268

answers:

5

if yes,what is the relation?

A: 

A single CPU (core) can run only one thread at once.

If you have more threads than CPUs, they will be scheduled using some sort of time slicing algorithm.

Kevin Peterson
A: 

A thread is a unit of work assigned to a CPU core.

At any given moment any thread is either suspended (not running) or is running on exactly one core. Every core is either idle (not running any thread) or is running exactly one thread.

Assigning threads to cores is the operating system scheduler job.

sharptooth
A: 

A single thread can be run by a CPU at a time, that is why when you make a multi-threaded application the concept of dual-core or multi-core can be utilized to paraller process your program units.

Bhaskar
+8  A: 

Think of a CPU as a person, and a Thread as a single task that person has to perform.

For instance, if one person tries to wash the dishes, prepare breakfast, put clothes on the children, and make sure the cat doesn't eat the dog food, that person has to switch back and forth between tasks rapidly, in order to have some progress on all tasks seemingly at the same time.

But that person can only do one thing at a time.

Lasse V. Karlsen
Pig-swill! My wife can do all that, and more, with true concurrency, except we don't have a cat or dog :-) +1.
paxdiablo
Maybe your wife is a hyperthreading, multi-core CPU? :)
Thorarin
Maybe *Pax* is a mormon
oxbow_lakes
Note that I did not imply that the person in question was a woman. Since programmers rarely see women, I assumed the person would be a man, and it's a well known fact that men can only do one thing at a time, or so I'm told. I don't know, I'm currently typing so I can't recall that fact from memory.
Lasse V. Karlsen
A: 

There are multiple relation possible, depending on your system architecture:

  • for single processor case, the relation is 1:N (where N is the number of threads). Everything will be run on that single processor
  • for multi processor/multi core/hyperthreading case, the relation is approximately P:N (where P is the number of processors), however, the thread exectution becomes a 'multi-dimensional' scheduling problem.

Your operating system's thread scheduler will make effort to distribute the threads among the available processing units, based on runtime characteristics (used cpu cycles, blockedness), user preferences (affinity, thread(s) serving the active window) and other properties.

For example, if you have 1 intensive computational thread and 10 I/O thread with lots of waits, the OS scheduler will most likely assign T1 to P1 and T2-T11 to P2 and power down the rest of the cores for energy saving and cache-redistribution to favor P1. T1 will become the entire core for its use and does not get preempted by T2-T11.

kd304