affiliate_link

Wednesday, May 21, 2014

Multithreading Multiprocessor vs Single-Processor Computers

Multiprocessor Computers

Multithreading provides greater throughput. Ten processors can do ten times the work of one, but only if the work is divided so that all ten can be working at once; threads provide an easy way to divide the work and exploit the extra processing power. If you use multithreading on a multiprocessor computer:
  • The number of threads that can execute concurrently is limited by the number of processors.
  • A background thread executes only when the number of foreground threads executing is smaller than the number of processors.
  • When you call the Thread.Start method on a thread, that thread might or might not start executing immediately, depending on the number of processors and the number of threads currently waiting to execute.
  • Race conditions can occur not only because threads are preempted unexpectedly, but because two threads executing on different processors might be racing to reach the same code block.

Single-Processor Computers 

Multithreading provides greater responsiveness to the computer user, and uses idle time for background tasks. If you use multithreading on a single-processor computer:
  • Only one thread runs at any instant.
  • A background thread executes only when the main user thread is idle. A foreground thread that executes constantly starves background threads of processor time.
  • When you call the Thread.Start method on a thread, that thread does not start executing until the current thread yields or is preempted by the operating system.
  • Race conditions typically occur because the programmer did not anticipate the fact that a thread can be preempted at an awkward moment, sometimes allowing another thread to reach a code block first.

No comments: