User account creation filtered due to spam.
Without -pthread, the constructor of std::thread always throws std::system_error. While this was apparently the resolution to bug 42198, simply throwing an error with the code 'operation_not_permitted' is rather mystifying to someone who isn't aware of the problem in the first place.
Would it be possible to offer a more descriptive error, preferably at compile time?
The problem is that not all targets need -pthread, or some which do need it spell it differently, and not all platforms define _REENTRANT when the option is used, so there's no reliable way to do what you're asking for.
Would it be possible to at least make the exception that is being thrown more descriptive? I had guessed that some kind of compile-time warning might be impossible, but my main concern is that the exception that gets thrown offers little insight on what the problem might be.
Probably, something in the docs could be also useful.
We could fix this just by overloading __throw_system_error to take a string:
"Enable multithreading support to use std::thread");
then passing that to the std::system_error constructor.
That would give something like:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading support to use std::thread: Operation not permitted
Aborted (core dumped)
That, if feasible, would be perfect.
Entirely feasible, and probably safe enough for the 4.6 and 4.7 branches too.
Date: Sun Aug 12 18:57:53 2012
New Revision: 190330
* src/c++11/thread.cc (thread::_M_start_thread): Improve error text
when threads are not enabled.
fixed for 4.8