title: MinGW and std::thread
body: <p>So I've been trying to get the following code to compile and run on Windows by using a MinGW compiler.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  
  void test()
  {
      std::cout &lt;&lt; "test" &lt;&lt; std::endl;
  }
  
  int main()
  {
      std::thread t(test);
  }
  </code></pre>
  
  <p>I'm compiling with the following command:</p>
  
  <pre><code>g++ -std=c++11 test.cpp -o test.exe
  </code></pre>
  
  <p>Now the problem is the version of MinGW one should use and I've tried about all the versions I know of.</p>
  
  <ol>
  <li>MinGW-builds: <a href="http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.0/32-bit/threads-win32/sjlj/" rel="noreferrer">thread-win32</a></li>
  <li>MinGW-builds: <a href="http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.0/32-bit/threads-posix/sjlj/" rel="noreferrer">thread-posix</a></li>
  <li>MinGW-w64: <a href="http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-4.8-experimental-stdthread/" rel="noreferrer">stdthread experimental rubenvb</a></li>
  <li>MinGW-w64: <a href="http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-dw2-4.7-experimental-stdthread/" rel="noreferrer">stdthread experimental rubenvb 4.7</a></li>
  </ol>
  
  <p>Number 1 doesn't work, since GCC <a href="http://www.cplusplus.com/forum/general/76836/#msg412938" rel="noreferrer">apparently only supports</a> pthread stuff internally.</p>
  
  <p>Number 2 does compile and it essentially even outputs <code>test</code> (see the last line of the output), but it also crashes with the error:</p>
  
  <pre><code>terminate called without an active exception
  
  This application has requested the Runtime to terminate it in an unusual way.
  Please contact the application's support team for more information.
  test
  </code></pre>
  
  <p>Number 3 and 4 again do compile, but they don't output <code>test</code> and instead instantly crashes, but with a more descriptive output:</p>
  
  <pre><code>terminate called after throwing an instance of 'std::system_error'
    what():  Enable multithreading to use std::thread: Operation not permitted
  
  This application has requested the Runtime to terminate it in an unusual way.
  Please contact the application's support team for more information.
  </code></pre>
  
  <p>Google brought me of course to the <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52681" rel="noreferrer">GCC bug tracker</a> and some other posts, that suggested to use <code>-pthread</code>, which doesn't help at all.</p>
  
  <p>I've also tried manually linking against <code>winpthread</code> and <code>pthread</code>, but that doesn't do anything either.</p>
  
  <p>There's also no difference between <code>-std=c++11</code> and <code>-std=gnu++11</code>...</p>
  
  <p>I'm really lost right now and don't know, if it's at all possible to get a MinGW version, that supports <code>std::thread</code>, but maybe I'm just overlooking some compiler flags. I hope someone out there can help me!</p>