public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ro at CeBiTec dot Uni-Bielefeld.DE" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/51296] Several 30_threads tests FAIL on Tru64 UNIX
Date: Thu, 12 Jan 2012 15:48:00 -0000	[thread overview]
Message-ID: <bug-51296-4-0vZLDFSa1y@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-51296-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51296

--- Comment #21 from ro at CeBiTec dot Uni-Bielefeld.DE <ro at CeBiTec dot Uni-Bielefeld.DE> 2012-01-12 15:47:53 UTC ---
> --- Comment #20 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-11 17:48:25 UTC ---
> (In reply to comment #19)
>> I've just tried it with the vendor cxx (first disabling noexcept for C++
>> < 2011), and it also fails with EINVAL.
>
> Well that's something vaguely positive at least ... the root cause probably
> isn't a G++ front-end issue or libstdc++ issue.

True, though I still don't understand why it wouldn't work in C++ when a
similar C testcase does.

>> Given that this is mostly autoconf work, I could give it a try myself if
>> I can figure out where best to override the __GTHREAD_MUTEX_INIT
>> definition from gthr-default.h/gthr-posix.h.  The problem seems to be
>> that autoconf results go into <bits/c++config.h>, which is included way
>> before <bits/gthr.h>.
>
> Yes, that's why I thought of making it depend on some new
> _GLIBCXX_BROKEN_GTHREAD_MUTEX_INIT macro set in <bits/c++config.h> by autoconf,
> rather trying to alter gthr-posix.h
>
> then e.g.
>
>    class __mutex_base
>    {
>    protected:
>      typedef __gthread_mutex_t           __native_type;
>
> -#ifdef __GTHREAD_MUTEX_INIT
> -#if defined __GTHREAD_MUTEX_INIT && !defined
> _GLIBCXX_BROKEN_GTHREAD_MUTEX_INIT
>      __native_type  _M_mutex = __GTHREAD_MUTEX_INIT;
>
>      constexpr __mutex_base() noexcept = default;
> #else
>      __native_type  _M_mutex;

Unfortunately, we still need to provide __GTHREAD_MUTEX_INIT_FUNCTION,
and it seems best to do so in gthr-posix.h directly, as is done in
gthr-dce.h.  Here's the patch I came up with so far.  gthr-posix.h has
Tru64 UNIX-specific code already, so this isn't much worse that what we
already have.  __GTHREAD_COND_INIT has the same issue, so it needs the
same workaround.

The std/mutex change is a hack to avoid

In file included from
/var/gcc/regression/trunk/5.1b-gcc/build/alpha-dec-osf5.1b/libstdc++-v3/include/future:40:0,
                 from
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/30_threads/async/async.cc:27:
/var/gcc/regression/trunk/5.1b-gcc/build/alpha-dec-osf5.1b/libstdc++-v3/include/mutex:160:5:
error: function 'std::mutex::mutex()' defaulted on its first declaration with
an exception-specification that differs from the implicit declaration
'std::mutex::mutex()'

and the condition_variable.cc change accounts for the fact that gthr.h
only documents __GTHREAD_COND_INIT_FUNCTION (analogous to
__GTHREAD_MUTEX_INIT_FUNCTION), not __gthread_cond_init.

--- gthr-posix.h.dist    Sat Jan  7 00:12:15 2012
+++ gthr-posix.h    Thu Jan 12 13:50:52 2012
@@ -62,7 +62,13 @@ typedef struct timespec __gthread_time_t
    in gthr.h for details. */
 #define __GTHREAD_HAS_COND    1

+#ifndef __osf__
 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
+#define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
+#else
+#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
+#define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function
+#endif
 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
@@ -71,7 +77,6 @@ typedef struct timespec __gthread_time_t
 #else
 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
__gthread_recursive_mutex_init_function
 #endif
-#define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
 #define __GTHREAD_TIME_INIT {0,0}

 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
@@ -730,6 +735,20 @@ __gthread_setspecific (__gthread_key_t _
   return __gthrw_(pthread_setspecific) (__key, __ptr);
 }

+static inline void
+__gthread_mutex_init_function (__gthread_mutex_t *__mutex)
+{
+  if (__gthread_active_p ())
+    __gthrw_(pthread_mutex_init) (__mutex, NULL);
+}
+
+static inline void
+__gthread_cond_init_function (__gthread_cond_t *__cond)
+{
+  if (__gthread_active_p ())
+    __gthrw_(pthread_cond_init) (__cond, NULL);
+}
+
 static inline int
 __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
 {
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -157,7 +157,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #ifdef __GTHREAD_MUTEX_INIT
     constexpr
 #endif
-    mutex() noexcept = default;
+    //    mutex() noexcept = default;
+    mutex() = default;
     ~mutex() = default;

     mutex(const mutex&) = delete;
diff --git a/libstdc++-v3/src/condition_variable.cc
b/libstdc++-v3/src/condition_variable.cc
--- a/libstdc++-v3/src/condition_variable.cc
+++ b/libstdc++-v3/src/condition_variable.cc
@@ -36,10 +36,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #else
   condition_variable::condition_variable() noexcept
   {
-    int __e = __gthread_cond_init(&_M_cond, 0);
-
-    if (__e)
-      __throw_system_error(__e);
+    __GTHREAD_COND_INIT_FUNCTION(&_M_cond);
   }

   condition_variable::~condition_variable() noexcept

I've rebuilt libstdc++.so with those changes and am currently rerunning
the testsuite.  The previously failing 30_threads testcases pass now.

Would this approach (with a proper fix in <mutex> instead of the hack)
be appropriate from the C++ view?  I'll include something along this
line in this weekend's bootstrap and see if it causes other problems.

    Rainer


  parent reply	other threads:[~2012-01-12 15:48 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-24 18:08 [Bug libstdc++/51296] New: " ro at gcc dot gnu.org
2011-11-24 19:27 ` [Bug libstdc++/51296] " redi at gcc dot gnu.org
2011-11-24 20:30 ` redi at gcc dot gnu.org
2011-11-24 21:37 ` redi at gcc dot gnu.org
2011-11-25 14:13 ` ro at CeBiTec dot Uni-Bielefeld.DE
2011-11-25 14:36 ` ro at CeBiTec dot Uni-Bielefeld.DE
2011-11-25 14:47 ` ro at CeBiTec dot Uni-Bielefeld.DE
2011-11-25 15:17 ` redi at gcc dot gnu.org
2011-11-25 15:18 ` redi at gcc dot gnu.org
2011-11-25 15:21 ` ro at CeBiTec dot Uni-Bielefeld.DE
2011-11-25 15:22 ` redi at gcc dot gnu.org
2011-11-25 16:26 ` ro at CeBiTec dot Uni-Bielefeld.DE
2011-11-26 15:24 ` redi at gcc dot gnu.org
2011-11-26 16:03 ` redi at gcc dot gnu.org
2011-11-28 13:24 ` ro at CeBiTec dot Uni-Bielefeld.DE
2011-11-28 14:35 ` redi at gcc dot gnu.org
2011-11-28 14:40 ` ro at CeBiTec dot Uni-Bielefeld.DE
2011-11-28 15:10 ` redi at gcc dot gnu.org
2012-01-11 16:50 ` redi at gcc dot gnu.org
2012-01-11 17:38 ` ro at CeBiTec dot Uni-Bielefeld.DE
2012-01-11 17:49 ` redi at gcc dot gnu.org
2012-01-12 15:48 ` ro at CeBiTec dot Uni-Bielefeld.DE [this message]
2012-01-12 16:16 ` redi at gcc dot gnu.org
2012-01-12 18:18 ` ro at CeBiTec dot Uni-Bielefeld.DE
2012-01-13 10:34 ` ro at CeBiTec dot Uni-Bielefeld.DE
2012-01-13 10:54 ` redi at gcc dot gnu.org
2012-01-16 19:37 ` ro at CeBiTec dot Uni-Bielefeld.DE
2012-01-16 19:52 ` redi at gcc dot gnu.org
2012-01-31 12:48 ` ro at gcc dot gnu.org
2012-01-31 20:04 ` redi at gcc dot gnu.org
2012-02-01 10:24 ` ro at CeBiTec dot Uni-Bielefeld.DE
2012-02-01 10:59 ` redi at gcc dot gnu.org
2012-02-03  8:50 ` redi at gcc dot gnu.org
2012-02-03  8:52 ` redi at gcc dot gnu.org
2012-02-03  9:48 ` ro at CeBiTec dot Uni-Bielefeld.DE
2012-02-03  9:51 ` ro at CeBiTec dot Uni-Bielefeld.DE
2012-02-07  9:20 ` redi at gcc dot gnu.org
2012-02-07  9:23 ` redi at gcc dot gnu.org
2012-02-10 17:01 ` ro at CeBiTec dot Uni-Bielefeld.DE
2012-02-10 18:11 ` ro at gcc dot gnu.org
2012-02-10 18:14 ` ro at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-51296-4-0vZLDFSa1y@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).