title: Multithreading on a multi core machines not maxing CPU
body: <p>I am working on maintaining someone else's code that is using multithreading, via two methods:</p>
  
  <pre><code>1: ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ReadData), objUpdateItem)
  
  2: Dim aThread As New Thread(AddressOf LoadCache)
     aThread.Start()
  </code></pre>
  
  <p>However, on a dual core machine, I am only getting 50% CPU utlilization, and on a dual core with hyperthreadin enabled machine, I am only getting 25% CPU utilization.</p>
  
  <p>Obviously threading is extremely complicated, but this behaviour would seem to indicate that I am not understanding some simple fundamental fact?</p>
  
  <h2>UPDATE</h2>
  
  <p>The code is too horribly complex to post here unfortunately, but for reference purposes, here is roughly what happens....I have approx 500 Accounts whose data is loaded from the database into an in memory cache...each account is loaded individually, and that process first calls a long running stored procedure, followed by manipulation and caching of the returned data.  So, the point of threading in this situation is that there is indeed a bottleneck hitting the database (ie: the thread will be idled for up to 30 seconds waiting for the query to return), so we thread to allow others to begin processing the data they have received from Oracle.</p>
  
  <p>So, the main thread executes:  </p>
  
  <pre><code>ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ReadData), objUpdateItem) 
  </code></pre>
  
  <p>Then, the ReadData() then proceeds to execute (exactly once):  </p>
  
  <pre><code>Dim aThread As New Thread(AddressOf LoadCache)
  aThread.Start()
  </code></pre>
  
  <p>And this is occurring in a recursive function, so the QueueUserWorkItem can be executing multiple times, which in turn then executes <em>exactly one</em> new thread via the aThread.Start  </p>
  
  <p>Hopefully that gives a decent idea of how things are happening.</p>
  
  <p>So, under this scenario, should this not theoretically pin <em>both</em> cores, rather than maxing out at 100% on one core, while the other core is essentially idle?</p>