32

I opted for the Win32 threading model when installing the MinGW-w64 toolchain, after reading that it provides better performance than the POSIX counterpart. I am not qualified for benchmarking this claim myself, but here's a source.

At first I thought this option would only affect the inner workings of the GCC runtime, while not preventing me from using C++11 threads in my code, based on this answer and this comment by fellow user rubenvb.

However, this doesn't seem to be the case. std::thread support appears to be non-existent in this MinGW-w64 installation.

I'm invoking g++ from the command line with no options other than -std=c++11.

At this point I'm not sure if:

  • rubenvb was mistaken, and it's actually necessary to install MinGW-w64 under the POSIX threading model in order to compile my code which depends on the C++11 thread library, or;
  • I completely misunderstood it all, or;
  • std::thread is actually supported in my scenario, it's just not intuitive.

I reinforce the "out of the box" part in the title. There exists a library called mingw-std-threads, as presented in this answer. However, as a third-party option, it is not relevant to this question.

So, as of today (May 2016), does MinGW-w64 nativelly support std::thread depending code, when installed with the Win32 internal threading model?

4
  • installing mingw-std-threads as you linked to, works and takes about 30 seconds Commented May 21, 2016 at 4:33
  • 2
    @M.M ... Thanks for the suggestion, I did that already. This question is mainly for the sake of curiosity/canonicity, however. Information seem to diverge between different sources. Commented May 21, 2016 at 4:39
  • Neither my answer nor my comment are wrong. They were written in a time where the mingw-std-threads library wasn't available (or at least I wasn't aware of it). GCC with its internal threading model set to win32 does not support C++11 threading functionality, period. My answer you linked says exactly this. My comment on the other hand doesn't talk about C++11 thread support. Instead, it deals with calling pthreads or win32 thread related functions with GCC built with win32/posix as its internal threading model, which all works as one would expect. These are two very different topics. Commented Jun 5, 2016 at 0:15
  • Hi @rubenvb, thank you for your input. It seems then that Point 2 - "I completely misunderstood it all" - is the case. I didn't pay proper attention to the fact that you refer to the term "API". Commented Jul 13, 2016 at 6:37

2 Answers 2

32

To use the MinGW-w64 with Win32 native threads you can install the mingw-std-threads headers.

As described on that page, this is because MinGW-w64 is a port of GCC, but GCC does not include any native thread support. Instead GCC installations typically implement threading via either gthreads or pthreads as a part of glibc. MinGW-w64 does not include a port of glibc. (Instead it uses a combination of the MSVC runtime, plus its own code to fill in holes).

Also as described on that page, recent versions of MinGW-w64 do include a Win32 port of pthreads ("winpthreads"), which explains why you can have threads work "out of the box" by selecting the "pthread" model from the MinGW-w64 installer.

Sign up to request clarification or add additional context in comments.

Comments

3

The win32 threading model has been rewritten in GCC 13, and since then it supports C++11 std::thread out of the box:

https://gcc.gnu.org/gcc-13/changes.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.