title: Dual-Core Hyperthreading: Should I use 4 threads or 3 or 2?
body: <p>If you're spawning multiple threads (or processes) concurrently, is it better to spawn as many as the number of <em>physical</em> processors or the number of <em>logical</em> processors, assuming the task is CPU-bound? Or is it better to do something in between (say, 3 threads)?</p>
  
  <p>Does the performance depend on the kind of instructions that are getting executed (say, would non-local memory access be much different from cache hits)? If so, in which cases is it better to take advantage of hyperthreading?</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>The reason I'm asking is, I remember reading somewhere that if you have as many tasks as the number of virtual processors, tasks on the same physical core can sometimes starve some CPU resources and prevent each other from getting as many resources as needed, possibly decreasing performance. That's why I'm wondering if having as many threads as virtual cores is a good idea.</p>