1

I am trying to make a basic multithreaded application in c++ using the g++ compiler (mingw32 9.2.0). The code I am using:

#include <iostream>
#include <thread>

int N = 0;
void dostuff() {
    N++;
}

int main() {
    std::thread t(dostuff);
    std::cout << N;

}

However, this simple code fails to compile, with g++ saying 'thread' is not a member of 'std' (compiling with g++ -pthread -std=c++0x test.cpp -o test, and also hilariously saying did you forget to '#include <thread>', and showing corrected code with #include <thread> right below where I put it! You can see that here.

I am at a complete loss as to why this doesn't work - I have searched around, using this article and also this one, to no avail.

Alice F
  • 435
  • 5
  • 13
  • 3
    The plain MinGW doesn't support threads, you want MinGW-w64. There are several distributions, the good ones are https://www.msys2.org/ and https://winlibs.com/ – HolyBlackCat Jul 20 '21 at 18:39

0 Answers0