Problems with C++ threads

Asked

Viewed 236 times

2

Hello, I’m using mingw, 32-bit version in windows 7 Ultimate and I’m having trouble using threads.
I know they don’t work for this version of mingw, which is why I use the version in this link. But I don’t 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, tested on this site and worked this example, someone could tell me why this happens?

#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;
}
  • 2

    Herm.. And what’s the problem?

  • @Kahler edited the post.

  • What were the flags/flags you passed to mingw?

  • @Márioferoldi I didn’t pass any flag and already tried with the tag -pthread, unsuccessfully, and had already found this post when I went looking for the answer.

  • @Simplecoder I adjusted the link you provided to contain your example code (it will appear when some editor approves).

Show 1 more comment

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 he only tested it for Mingw-W64 5.3.0, and warns that platform detection macros can have to be adjusted manually for some versions of Windows.

The error you posted is related to a missing statement, you included 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 that’s not the problem, and you’re willing and able to use another distribution for Windows, which already contains built-in threads (recommend), here are some open options:

  • TDM GCC, comes with GCC version 5.1.0 (very easy to install and use)
  • Mingw-W64, comes with GCC 7.3
  • Still not working, says fatal error: mingw.thread. h: No such file or directory.

  • Well, if you translate this error into English: "mingw.thread. h: Nonexistent file or directory, "which means you did not add the files during its compilation, or provided wrong path...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.