0

I'm using mingw64 and even a simple program like this failed to compile. Moreover g++ is suggesting a revolutionary solution.

The code-

#include <mutex>

int main()
{
  std::mutex m;
}

The error-

test.cpp: In function 'int main()':
test.cpp:5:8: error: 'mutex' is not a member of 'std'
   std::mutex m;
    ^~~~~

The solution-

test.cpp:5:8: note: 'std::mutex' is defined in header '<mutex>'; did you forget to'#include <mutex>'?
test.cpp:2:1:
+#include <mutex>
 
test.cpp:5:8:
   std::mutex m;
        ^~~~~

How do I compile this?

vector X
  • 89
  • 7

1 Answers1

0

Solved!

C++11 or C11 Multithreading features are only supported by POSIX threads

Threading I am using is win32 which does not support Multithreading. So, std::thread and std::mutex will not work!

However to get std::thread working, use this mingw-std-threads.

I simply replaced my initial mingw installation with x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z

You may find binaries here.

vector X
  • 89
  • 7