title: std::mutex not locking properly for std::cout
body: <p>I'm learning about multithreading in C++11 and I tried this simple test but the output is not what I expected.</p>
  
  <pre><code>#include &lt;thread&gt;
  #include &lt;iostream&gt;
  #include &lt;mutex&gt;
  
  int main() {
      auto function = [](int x) {
          std::mutex m;
          m.try_lock();
          std::cout &lt;&lt; "Hello" &lt;&lt; x &lt;&lt; std::endl;
          m.unlock();
          return;
      };
      std::thread t1(function , 1);
      std::thread t2(function, 2);
      std::thread t3(function, 3);
      std::thread t4(function, 4);    
  
      t1.join();
      t2.join();
      t3.join();
      t4.join();
  
      std::cin.get();
      return 0;
  }
  </code></pre>
  
  <p>I expected the output to be: </p>
  
  <pre><code>Hello1
  Hello2
  Hello3
  Hello4
  </code></pre>
  
  <p>(maybe not in that order but each hello and number in a separate line)</p>
  
  <p>Instead I got something like this:</p>
  
  <pre><code>HelloHello21
  Hello3
  Hello4
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>HelloHello2
  1
  Hello3
  Hello4
  </code></pre>
  
  <p>What puzzles besides the mutex aparently not locking properly is that it's always the Hello1 the one that gets cut in half.</p>
  
  <p>EDIT: done in VS2015 if it makes any difference (should not because it's all standard?)</p>