Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 threading on Windows

Is there anyway to use std::thread with C++11 standard library in windows when compiling with g++ 4.5.2 in MinGW?

I'm going assume no as I've seen many things saying you have to compile with the pthreads option but I figure I'd ask anyway.

like image 668
csteifel Avatar asked Jul 21 '11 22:07

csteifel


2 Answers

There is experimental support for std::thread in for MinGW-w64 toolchains.

Specifically, my GCC 4.6 builds provide usable std::thread through MinGW-w64's winpthreads library.

You can find downloads here:

  • 64-bit.
  • 32-bit.

Apart from that, MSVC11 (Visual Studio 2012) has <thread>, <chrono>, and <atomic>. You can download the Express edition here.

like image 91
rubenvb Avatar answered Oct 19 '22 18:10

rubenvb


There is already a lightweight native implementation of std::thread and sync primitives: https://github.com/meganz/mingw-std-threads

IT is a header-only library and should work with any C++11 compliant version of MinGW. You just need to include the headers in your code.

like image 39
Alexander Vassilev Avatar answered Oct 19 '22 19:10

Alexander Vassilev