Bug 50196 - [C++0x] std::thread not available under macos
Summary: [C++0x] std::thread not available under macos
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.6.2
: P3 enhancement
Target Milestone: 4.7.0
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-26 14:54 UTC by watsonsong
Modified: 2012-01-28 19:08 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-08-27 00:00:00


Attachments
patch for configure (553 bytes, patch)
2011-10-21 00:15 UTC, Jonathan Wakely
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description watsonsong 2011-08-26 14:54:13 UTC
I try to use std::thread on MacOS X 10.6.8.
As the library is a new feather in c++0x, I use compile flag -std=c++0x, but it can not find std::thread when I include thread header file.
I find the _GLIBCXX_HAS_GTHREADS is not defined, and that because _POSIX_TIMEOUTS is not defined on MacOS and there is no implement of pthread_mutex_timedlock.
Can libstdc++ is more portable, if boost::thread is avaiable on MacOS, I wish the g++ can support it natively.
Comment 1 Jonathan Wakely 2011-08-26 16:06:00 UTC
It would be possible to define _GLIBCXX_HAS_GTHREADS without _POSIX_TIMEOUTS, so that <thread> is available, and most of <mutex> too.  I think only the Timed Mutex types require _POSIX_TIMEOUTS, so there's a lot of useful functionality that doesn't require it.

We could have _GLIBCXX_HAS_GTHREADS and _GLIBCXX_HAS_TIMED_MUTEXES, with only the second depending on _POSIX_TIMEOUTS
Comment 2 watsonsong 2011-08-27 14:36:44 UTC
I use macport to install gcc4.6 on my computer, and I add -D_GLIBCXX_HAS_GTHREADS flag to g++ and it report errors:

/opt/local/include/gcc46/c++/x86_64-apple-darwin10/bits/c++config.h:159:20: error: 'NULL' was not declared in this scope
/opt/local/include/gcc46/c++/x86_64-apple-darwin10/bits/c++config.h:159:38: error: invalid type in declaration bebore ';' token
/opt/local/include/gcc46/c++/mutex:276:52: error: there are no arguments to '__gthread_mutex_timedlock' that depend on a template parameter, so a declaration of '__gthread_mutex_timedlock' must be availiable [-fpermissive]
/opt/local/include/gcc46/c++/mutex:383:62: error: there are no arguments to '__gthread_recursive_mutex_timedlock' that depend on a template parameter, so a declaration of '__gthread_recursive_mutex_timedlock' must be availiable [-fpermissive]

It seems can not just define _GLIBCXX_HAS_GTHREADS.
Comment 3 Jonathan Wakely 2011-08-27 15:35:55 UTC
No, of course not.  That's not what I meant.

I mean we (the library maintainers) could define _GLIBCXX_HAS_GTHREADS in c++config.h when gthreads is available, and not require _POSIX_TIMEOUTS
Comment 4 Jonathan Wakely 2011-10-06 09:58:01 UTC
I'll look into doing this for 4.7
Comment 5 watsonsong 2011-10-08 06:30:52 UTC
(In reply to comment #4)
> I'll look into doing this for 4.7

Thank you.
Comment 6 Jonathan Wakely 2011-10-21 00:15:23 UTC
Created attachment 25564 [details]
patch for configure

could you test the patch at http://gcc.gnu.org/ml/gcc-patches/2011-10/msg01912.html ?

you'll also need this attached patch for configure
Comment 7 Jonathan Wakely 2011-10-22 21:31:28 UTC
Author: redi
Date: Sat Oct 22 21:31:24 2011
New Revision: 180329

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=180329
Log:
	PR libstdc++/50196
	* acinclude.m4 (GLIBCXX_HAS_GTHREADS): Don't depend on _POSIX_TIMEOUTS.
	* configure: Regenerate.
	* include/std/mutex (timed_mutex, recursive_timed_mutex): Define
	conditionally on GTHREADS_HAS_MUTEX_TIMEDLOCK.
	* testsuite/lib/libstdc++.exp (check_v3_target_gthreads_timed): Define.
	* testsuite/lib/dg-options.exp (dg-require-gthreads-timed): Define.
	* testsuite/30_threads/recursive_timed_mutex/dest/destructor_locked.cc:
	Use dg-require-gthreads-timed instead of dg-require-gthreads.
	* testsuite/30_threads/recursive_timed_mutex/native_handle/
	typesizes.cc: Likewise.
	* testsuite/30_threads/recursive_timed_mutex/native_handle/1.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/try_lock_until/1.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/try_lock_until/2.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/cons/assign_neg.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/cons/1.cc: Likewise.
	* testsuite/30_threads/recursive_timed_mutex/cons/copy_neg.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/requirements/typedefs.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/try_lock/1.cc: Likewise.
	* testsuite/30_threads/recursive_timed_mutex/try_lock/2.cc: Likewise.
	* testsuite/30_threads/recursive_timed_mutex/lock/1.cc: Likewise.
	* testsuite/30_threads/recursive_timed_mutex/lock/2.cc: Likewise.
	* testsuite/30_threads/recursive_timed_mutex/unlock/1.cc: Likewise.
	* testsuite/30_threads/recursive_timed_mutex/try_lock_for/1.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/try_lock_for/2.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/try_lock_for/3.cc:
	Likewise.
	* testsuite/30_threads/timed_mutex/dest/destructor_locked.cc: Likewise.
	* testsuite/30_threads/timed_mutex/native_handle/typesizes.cc:
	Likewise.
	* testsuite/30_threads/timed_mutex/native_handle/1.cc: Likewise.
	* testsuite/30_threads/timed_mutex/try_lock_until/1.cc: Likewise.
	* testsuite/30_threads/timed_mutex/try_lock_until/2.cc: Likewise.
	* testsuite/30_threads/timed_mutex/cons/assign_neg.cc: Likewise.
	* testsuite/30_threads/timed_mutex/cons/1.cc: Likewise.
	* testsuite/30_threads/timed_mutex/cons/copy_neg.cc: Likewise.
	* testsuite/30_threads/timed_mutex/requirements/standard_layout.cc:
	Likewise.
	* testsuite/30_threads/timed_mutex/requirements/typedefs.cc: Likewise.
	* testsuite/30_threads/timed_mutex/try_lock/1.cc: Likewise.
	* testsuite/30_threads/timed_mutex/try_lock/2.cc: Likewise.
	* testsuite/30_threads/timed_mutex/lock/1.cc: Likewise.
	* testsuite/30_threads/timed_mutex/unlock/1.cc: Likewise.
	* testsuite/30_threads/timed_mutex/try_lock_for/1.cc: Likewise.
	* testsuite/30_threads/timed_mutex/try_lock_for/2.cc: Likewise.
	* testsuite/30_threads/timed_mutex/try_lock_for/3.cc: Likewise.
	* testsuite/30_threads/unique_lock/cons/5.cc: Likewise.
	* testsuite/30_threads/unique_lock/cons/6.cc: Likewise.
	* testsuite/30_threads/unique_lock/locking/3.cc: Likewise.
	* testsuite/30_threads/unique_lock/locking/4.cc: Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/acinclude.m4
    trunk/libstdc++-v3/configure
    trunk/libstdc++-v3/include/std/mutex
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/cons/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/cons/assign_neg.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/cons/copy_neg.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/dest/destructor_locked.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/lock/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/lock/2.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/native_handle/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/native_handle/typesizes.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/requirements/typedefs.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock/2.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_for/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_for/2.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_for/3.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/2.cc
    trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/unlock/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/cons/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/cons/assign_neg.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/cons/copy_neg.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/dest/destructor_locked.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/lock/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/native_handle/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/native_handle/typesizes.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/requirements/standard_layout.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/requirements/typedefs.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock/2.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_for/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_for/2.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_for/3.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/2.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/unlock/1.cc
    trunk/libstdc++-v3/testsuite/30_threads/unique_lock/cons/5.cc
    trunk/libstdc++-v3/testsuite/30_threads/unique_lock/cons/6.cc
    trunk/libstdc++-v3/testsuite/30_threads/unique_lock/locking/3.cc
    trunk/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc
    trunk/libstdc++-v3/testsuite/lib/dg-options.exp
    trunk/libstdc++-v3/testsuite/lib/libstdc++.exp
Comment 8 Jonathan Wakely 2011-10-22 21:34:28 UTC
Should be fixed for 4.7 - std::timed_mutex and std::recursive_mutex are still not available, because they require a library function which darwin doesn't provide

This commit enables new tests for darwin which currently fail due to PR 50598, I assume they will pass when that's fixed
Comment 9 Jonathan Wakely 2011-10-24 19:33:32 UTC
I'm not sure if these failures are due to PR 50598:

FAIL: 30_threads/thread/native_handle/typesizes.cc execution test
FAIL: ext/mt_allocator/deallocate_global_thread-1.cc execution test
FAIL: ext/mt_allocator/deallocate_global_thread-3.cc execution test

The first one might be due to the dg-options for *-*-darwin not including -pthread (which I believe should be valid on both x86 and ppc darwin)
Comment 10 Jack Howarth 2012-01-28 18:56:03 UTC
(In reply to comment #8)
> Should be fixed for 4.7 - std::timed_mutex and std::recursive_mutex are still
> not available, because they require a library function which darwin doesn't
> provide
> 

Are you sure this is true of Lion? If you look at 3.ii.diff attached to PR51906, you will see that even when targeting the 10.6 API on Lion, the __GTHREAD_RECURSIVE_MUTEX_INIT is defined (unlike Snow Leopard).

 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51906#c12
Comment 11 Jonathan Wakely 2012-01-28 19:08:47 UTC
I think I meant to say std::timed_mutex and std::recursive_timed_mutex