[Mingw-users] Support for std::thread in libstdc++

Back to archive index
Eli Zaretskii eliz****@gnu*****
Thu Mar 14 01:59:28 JST 2019


> From: Keith Marshall <keith****@users*****>
> Date: Tue, 12 Mar 2019 22:06:06 +0000
> 
> On 12/03/19 15:41, Eli Zaretskii wrote:
> > Does anyone know what happens if a program is compiled that uses this
> > class?  Will it fail to compile, or abort at run time, or something
> > else?
> 
> I reviewed some of our historical archives, (my own local copies); it
> appears that, if GCC has been built with the win32 thread model, the
> class definition isn't exposed, so you get a compile time failure,
> diagnosed as "thread is not a member of std", or some such.

Yes, you are right.  For the record: the simple test program below
produces the following diagnostics:

  D:\usr\eli\data>g++ -c ./threaded-hello.cc
  ./threaded-hello.cc: In function 'int main()':
  ./threaded-hello.cc:12:8: error: 'thread' is not a member of 'std'
     std::thread t1(call_from_thread);
	  ^~~~~~
  ./threaded-hello.cc:12:8: note: suggested alternative: 'tera'
     std::thread t1(call_from_thread);
	  ^~~~~~
	  tera
  ./threaded-hello.cc:15:3: error: 't1' was not declared in this scope
     t1.join();
     ^~
  ./threaded-hello.cc:15:3: note: suggested alternative: 'tm'
     t1.join();
     ^~
     tm

Here's source code of the program I used:

#include <iostream>
#include <thread>

//This function will be called from a thread

void call_from_thread() {
  std::cout << "Hello, World" << std::endl;
}

int main() {
  //Launch a thread
  std::thread t1(call_from_thread);

  //Join the thread with the main thread
  t1.join();

  return 0;
}



More information about the MinGW-Users mailing list
Back to archive index