title: Unnecessary locking in STL? (Visual C++ Express)
body: <p>I'm trying to build a Tetris AI algorithm that can scale over multiple cores.</p>
  
  <p>In my tests it turns out that using multiple threads is slower than using a single thread.</p>
  
  <p>After some research I found that my threads spend most of their time waiting for <code>_Lockit _Lock(_LOCK_DEBUG)</code>. Here's a <a href="http://i.stack.imgur.com/XpTwd.png" rel="noreferrer">screenshot</a>.</p>
  
  <p>As you can see, the lock is applied on a <em>local variable</em>, which shouldn't require any locking anyway!</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Why does STL lock this vector?</li>
  <li>How can I make my program faster? (Use arrays?)</li>
  </ul>
  
  <h3>Update</h3>
  
  <p>I eliminated the lock by setting these command line options in my Visual Studio projects:</p>
  
  <pre><code>/D "_HAS_ITERATOR_DEBUGGING=0" /D "_SECURE_SCL=0"
  </code></pre>
  
  <p>It's important to apply this to all projects in the solution file or errors will occur at runtime (conflicting iterators etc).</p>
  
  <p>The second thing I changed was changing <code>std::vector&lt;bool&gt;</code> into <code>std::vector&lt;char&gt;</code>. I wasn't aware that <code>std::vector&lt;bool&gt;</code> was so slow.</p>