How to Enable Experimental C++11 Concurrency Features in Mingw

How to enable experimental C++11 concurrency features in MinGW?

To the best of my knowledge, MinGW does not support yet the new c++0x concurrency features (as of GCC 4.5). I remember reading a mailing list exchange in which it was pointed out that in MinGW the following ifdef from the thread header is not satisfied:

#if defined(_GLIBCXX_HAS_GTHREADS)

I guess this is somehow related to the way MinGW is built under Windows, whether it uses native threads or pthread, etc. In my code, I've written some minimal wrapping that uses Boost.thread instead of native c++0x threads when in Windows. The two interfaces are very similar and for many uses they can be swapped without issues.

EDIT: Thanks to Luc Danton for digging out the mailing list thread mentioned above:

http://comments.gmane.org/gmane.comp.gnu.mingw.user/33065

How to enable experimental C++11 concurrency features in MinGW?

To the best of my knowledge, MinGW does not support yet the new c++0x concurrency features (as of GCC 4.5). I remember reading a mailing list exchange in which it was pointed out that in MinGW the following ifdef from the thread header is not satisfied:

#if defined(_GLIBCXX_HAS_GTHREADS)

I guess this is somehow related to the way MinGW is built under Windows, whether it uses native threads or pthread, etc. In my code, I've written some minimal wrapping that uses Boost.thread instead of native c++0x threads when in Windows. The two interfaces are very similar and for many uses they can be swapped without issues.

EDIT: Thanks to Luc Danton for digging out the mailing list thread mentioned above:

http://comments.gmane.org/gmane.comp.gnu.mingw.user/33065

C++11 threading on Windows

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.

Does gcc 4.7.3 on cygwin support C++11 concurrency features?

You can try the following:

#include <thread>
#include <iostream>

using std::cout;
using std::endl;

main() {
#ifndef(_GLIBCXX_HAS_GTHREADS)
cout << "GThreads are not supported..." << endl;
#endif
}

In fact, as of GCC 4.4, _GLIBCXX_HAS_GTHREADS is undefined when libstdc++ is built because Cygwin implementation of pthread lacks some functionality. The same was true for MinGW.

NOTE: GThreads, which is directly used by std::thread, is a GCC wrapper around POSIX threads.

There are builds of MinGW-w64 based on GCC 4.7 and 4.8 targeting both 64-bit and 32-bit, which offer experimental support for std::thread. Furthermore, yes, of course Cygwin and MinGW can co-exist as long as you switch between these 2 environments correctly, i.e. do not mix them in the PATH environment variable.

Relevant links:

  • Thoughts on supporting the C++11 thread library on Windows;
  • GCC 4.4.0 - Can't activate threading support;
  • New Rubenvb GCC 4.8 std::thread enabled build.

GCC std::thread not found in namespace std

Works fine on Linux (g++ -std=c++0x -lpthread with no additional defines).

However, this thread on Cygwin mailing list suggests that, at least as of 4.4, _GLIBCXX_HAS_GTHREADS was disabled by an autoconf test when building libstdc++ because pthread implementation of cygwin is missing pthread_mutex_timedlock. Perhaps MinGW has the same problem.

Also, this thread on comp.lang.c++.moderated says the same thing. Not supported by the library.



Related Topics



Leave a reply



Submit