Bug 61841 - broken std::thread on Hurd
Summary: broken std::thread on Hurd
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 5.0
Assignee: Jonathan Wakely
URL: https://bugs.debian.org/749290
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-18 10:37 UTC by Gabriele Giacone
Modified: 2014-08-28 14:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-07-18 00:00:00


Attachments
testcase (232 bytes, text/x-c++src)
2014-07-18 10:37 UTC, Gabriele Giacone
Details
force dependency on pthread_create (302 bytes, patch)
2014-07-18 13:29 UTC, Jonathan Wakely
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriele Giacone 2014-07-18 10:37:02 UTC
Created attachment 33142 [details]
testcase

Forwarding Debian bug https://bugs.debian.org/749290
Attached testcase.

On hurd

$ g++ thread.cpp -pthread -std=c++11 -o thread
$ ./thread 
terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted
Aborted

On linux it runs fine

$ ./thread 
1307674368000
355687428096000
Comment 1 Jonathan Wakely 2014-07-18 13:29:40 UTC
Created attachment 33143 [details]
force dependency on pthread_create

Something like this would force the user to link to libpthread (turning a runtime error into a linktime error) and would force the linker to pull in the required symbol.
Comment 2 Jonathan Wakely 2014-08-13 18:40:42 UTC
Author: redi
Date: Wed Aug 13 18:40:10 2014
New Revision: 213922

URL: https://gcc.gnu.org/viewcvs?rev=213922&root=gcc&view=rev
Log:
	PR libstdc++/61841
	* include/std/thread (thread::_M_start_thread): Declare new overload.
	(thread::thread<_Callable, _Args...>): Call new overload with an
	explicit reference to pthread_create.
	* src/c++11/thread.cc (thread::_M_start_thread): Add new overload.
	* config/abi/pre/gnu.ver: Export new function.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/config/abi/pre/gnu.ver
    trunk/libstdc++-v3/include/std/thread
    trunk/libstdc++-v3/src/c++11/thread.cc
Comment 3 Jonathan Wakely 2014-08-13 18:41:50 UTC
This should be fixed on trunk, it would be great if someone can test it.
Comment 5 Jonathan Wakely 2014-08-28 12:24:35 UTC
The asm solution that Matthias applied to the Debian 4.8 branch should ensure that libpthread.so gets linked to, and so I would expect the __gthread_active_p() test that looks for __pthread_key_create to succeed even without Samuel's change.
Comment 6 Gabriele Giacone 2014-08-28 14:42:15 UTC
https://bugs.debian.org/749290#53

Please consider replying to its recipients.
Comment 7 Jonathan Wakely 2014-08-28 14:54:35 UTC
Ah I see, so Samuel's change is needed to make __gthread_active_p work on Hurd. We could have changed __gthread_active_p (as we've done e.g. for Bionic) but there's no point now.