Problems with threads in C ++

3
Hello, I'm using mingw, 32-bit version on windows 7 Ultimate and I'm having trouble using threads.
I know they do not work for this version of mingw, which is why I use the version on this link . But I do not compile this example because it says

  In static member function 'static unsigned int mingw_stdthread :: thread :: _ hardware_concurrency_helper ()':

  error: ':: GetNativeSystemInfo' has not been declared (in line 266)

This in the thread file I downloaded, I tested on this site and this example worked , could anyone tell me why this happened? / p>

#include <iostream>         // std::cout
#include <thread>           // std::thread

class test {
public:
    static void foo(){}
    static void bar(int x){}
    test(){
         std::thread first (foo);     // spawn new thread that calls foo()
         std::thread second (bar,0);  // spawn new thread that calls bar(0)
         first.join();                // pauses until first finishes
         second.join();               // pauses until second finishes
    }
};

int main() {
     test TESTE;
     return 0;
}
    
asked by anonymous 16.05.2018 / 23:17

1 answer

0

There are many different distributions of Mingw, some do not support threads directly and require the inclusion of platform-specific code. The page you posted contains these pieces of code, although the author states that they only tested for MinGW-w64 5.3.0, and warns that macros for platform detection can have to be manually adjusted for some versions of Windows.

The error you posted is related to a missing statement, did you include the required library according to the instructions?

  

This is a header-only library. To use, just include the corresponding mingw.xxx.h file, where xxx would be the name of the standard header that you would normally include.

You may need to declare in the code on your platform:

#include mingw.thread.h
#include <thread>

If this is not the problem, and you are willing and able to use another distribution for Windows that already contains embedded threads (I recommend), here are some options open:

  • TDM GCC , comes with GCC version 5.1.0 (very easy to install and use)
  • Mingw-w64 , comes with GCC 7.3
19.05.2018 / 20:02