c++11 std::async doesn’t work in mingw

Maybe it’s easier for me to interpret because I wrote that code, but it’s not so hard, just look at the first line of the error output:

swap.cpp:22:14: error: invalid use of incomplete type 'class std::future<std::basic_string<char> >'

That’s telling you that std::future is an incomplete type, i.e. it is declared but not defined. The next line tells you exactly where it’s declared (then all the other errors are caused by trying to use that incomplete type in different ways.)

If you look in GCC’s <future> header you’ll see that the types are declared near the top, but then the definitions are dependent on this preprocessor condition:

#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
  && (ATOMIC_INT_LOCK_FREE > 1)

If you compile some simple tests with those macros you’ll find out that _GLIBCXX_HAS_GTHREADS is not defined, and that’s because your gcc -v shows

Thread model: win32

No one has provided the necessary code to make the C++11 thread features work on Windows yet.

Making <future> work would be harder, but it’s not actually that difficult to enable <thread> and <mutex> but no one has stepped up to do the work yet. Yesterday I posted some ideas for how to enable the C++11 thread features for the win32 thread model: http://gcc.gnu.org/ml/libstdc++/2012-05/msg00020.html

Leave a Comment