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.
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
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.
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
I'll look into doing this for 4.7
(In reply to comment #4) > I'll look into doing this for 4.7 Thank you.
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
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
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
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)
(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
I think I meant to say std::timed_mutex and std::recursive_timed_mutex