3
votes

I am trying to implement mutlithreading in a C++11 program.

I separated the threading from my main program and tried to get the most basic example working:

#include <iostream>
#include <thread>

void first_procedure() {
    std::cout << "First procedure output." << std::endl;
}

void second_procedure() {
    std::cout << "Second procedure output." << std::endl;
}

int main() {
    std::thread first_thread(first_procedure);
    std::thread second_thread(second_procedure);
    first_thread.join();
    second_thread.join();
    return 0;
}

However, even with this example, I get the following error:

c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\thread In function 'bool std::operator<(std::thread::id, std::thread::id)':

88 30 c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\thread [Error] no match for 'operator<' (operand types are 'std::thread::native_handle_type {aka ptw32_handle_t}' and 'std::thread::native_handle_type {aka ptw32_handle_t}')

I am using the Orwell Dev-C++ 5.7.1 with TDM-GCC 4.7.1 64-bit on Windows 8. When calling the linker, I add -static-libgcc -std=c++11.

Edit 1: I joined the threads and get the same error message.

1
Note that your program is broken. You must not destroy a joinable thread.Kerrek SB
You need to join these threads.Jared Burrows
Is this the entire code? If so, your compiler is broken - get a new one.jweyrich
I edited my post. Even if I join the threads, I get the same error message. Yes, this is my entire code.wolx
TDM-GCC 4.7.1, and yet your included header is gcc\x86_64-w64-mingw32\ 4.8.1 \include ? I don't know how you pieced together that toolchain with chewing gum and bailing wire, but its f'ed up.WhozCraig

1 Answers

3
votes

This was noticed in the comments first:

From your error messages and supplementary details:

compiler: TDM-GCC 4.7.1
includes: gcc\x86_64-w64-mingw32\4.8.1\include

Your compiler is attempting to use libraries that are for a different compiler. Either use 4.7.1 or 4.8.1, not a mix of the two.

The good news is that your code looks fine. Sort out the toolchain and it should compile without issue.