Re: [RFC 0/6] Demangle minimal symbol names in worker threads

Eli Zaretskii
2019-03-13T15:38:49Z

> Date: Tue, 12 Mar 2019 05:33:30 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> CC: gdb-patches@sourceware.org
>
> > I asked around and learned that std::thread should work fine if you have
> > winpthreads, which apparently is used by default for mingw-w64.
> >
> > I don't actually know much about the mingw world, so I don't know if
> > that is good enough or not. Could you say?
>
> I could try.

Here's the answer. The simple test program attached at the end
doesn't compile:

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

So I think only MinGW64 might have support for std::thread,
mingw.org's MinGW (which is what I'm using) definitely doesn't.

> But regardless, I think we should allow for ports whose
> std::thread is not up to the task, because evidently this is a
> problematic area of libstdc++. It is IMO better to allow running this
> code in a single thread than breaking the entire build on some
> platform because other platforms might benefit from multiple execution
> cores.

This is still true. We could detect at configure time that
std::thread isn't supported and revert to serial alternative code
instead. Is that reasonable? If that is deemed too much of a
maintenance burden, I could perhaps, with some guidance, implement a
simple replacement using Win32 primitives, if all we need is to start
a thread and then do the thread-join thing. Let me know what you
think.

Here's the program I used to test this:

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