title: valgrind checking simple multithreading c++11 get sig11 error
body: <p>I use valgrind to check a simple c++11 multithreading program. It suppose not get any error but it does.</p>
  
  <p>source code as following</p>
  
  <pre><code>// test_main.cpp
  
  #include &lt;thread&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  std::mutex gMutex;
  
  void PrintLoop(const std::string&amp; str, const uint32_t&amp; time)
  {
      for (uint32_t i=0; i&lt;time; i++) {
          gMutex.lock();
          std::cout &lt;&lt; str &lt;&lt; ": " &lt;&lt; i &lt;&lt; std::endl;
          gMutex.unlock();
      }
  }
  
  int main(int argc, char* argv[])
  {
      std::thread t0(&amp;PrintLoop, "Thread0", 100);
      std::thread t1(&amp;PrintLoop, "Thread1", 100);
  
      t0.join();
      t1.join();
      return 0;
  }
  </code></pre>
  
  <p>I use MacOS, and I compile the source code with following command</p>
  
  <pre><code>g++ --std=c+=11 -g test_mian.cpp
  </code></pre>
  
  <p>and execute with following command</p>
  
  <pre><code>valgrin ./a.out
  </code></pre>
  
  <p>I got following error</p>
  
  <pre><code>==5003== Process terminating with default action of signal 11 (SIGSEGV)
  ==5003==  Access not within mapped region at address 0x700002ED903E
  ==5003==    at 0x10053A351: _pthread_find_thread (in /usr/lib/system/libsystem_pthread.dylib)
  ==5003==    by 0x10053B835: _pthread_join_cleanup (in /usr/lib/system/libsystem_pthread.dylib)
  ==5003==    by 0x10053B7C3: pthread_join (in /usr/lib/system/libsystem_pthread.dylib)
  ==5003==    by 0x10005BE94: std::__1::thread::join() (in /usr/lib/libc++.1.dylib)
  ==5003==    by 0x10000145B: main (test_main.cpp:21)
  ==5003==  If you believe this happened as a result of a stack
  ==5003==  overflow in your program's main thread (unlikely but
  ==5003==  possible), you can try to increase the size of the
  ==5003==  main thread stack using the --main-stacksize= flag.
  ==5003==  The main thread stack size used in this run was 8388608.
  ==5003==
  ==5003== HEAP SUMMARY:
  ==5003==     in use at exit: 26,424 bytes in 188 blocks
  ==5003==   total heap usage: 259 allocs, 71 frees, 32,336 bytes allocate
  ==5003==
  
  Memcheck: mc_leakcheck.c:1106 (void lc_scan_memory(Addr, SizeT, Bool, Int, Int, Addr, SizeT)): Assertion 'bad_scanned_addr &gt;= VG_ROUNDUP(start, sizeof(Addr))' failed.
  
  host stacktrace:
  ==5003==    at 0x238041866: ???
  ==5003==    by 0x238041C72: ???
  ==5003==    by 0x238041C55: ???
  ==5003==    by 0x238002FB1: ???
  ==5003==    by 0x23800288C: ???
  ==5003==    by 0x2380016DD: ???
  ==5003==    by 0x23800EACD: ???
  ==5003==    by 0x23804D221: ???
  ==5003==    by 0x2380CB127: ???
  
  sched status:
    running_tid=1
  </code></pre>
  
  <p>Why would this happend? Is there anything wrong with this source code?</p>