From: Jonathan Wakely <jwakely@redhat.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: "Martin Sebor" <msebor@gmail.com>,
libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org,
"François Dumont" <frs.dumont@gmail.com>
Subject: Re: [patch] Enable lightweight checks with _GLIBCXX_ASSERTIONS.
Date: Sun, 27 Sep 2015 15:14:00 -0000 [thread overview]
Message-ID: <20150927102432.GM12094@redhat.com> (raw)
In-Reply-To: <560704F4.3030203@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1596 bytes --]
On 26/09/15 22:49 +0200, Florian Weimer wrote:
>On 09/26/2015 09:52 PM, Jonathan Wakely wrote:
>
>> Would changes like this be suitable for _FORTIFY_SOURCE?
>
>> diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
>> index 5e5ced1..074bf26 100644
>> --- a/libstdc++-v3/include/std/mutex
>> +++ b/libstdc++-v3/include/std/mutex
>> @@ -70,7 +70,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> __recursive_mutex_base& operator=(const __recursive_mutex_base&) = delete;
>>
>> #ifdef __GTHREAD_RECURSIVE_MUTEX_INIT
>> +# if _GLIBCXX_ASSERTIONS && defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP)
>> + // Use an error-checking mutex type when assertions are enabled.
>> + __native_type _M_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
>> +# else
>> __native_type _M_mutex = __GTHREAD_RECURSIVE_MUTEX_INIT;
>> +# endif
>
>I think this is incorrect.
>
>If you try to lock an error-checking mutex recursively, the operation
>fails, and it does *not* increment the internal lock counter (the mutex
>may not even have one). This means a subsequent unlock operation will
>release the mutex too early.
>
>The trylock will be have differently, too.
>
>POSIX recursive mutexes are already error-checking in that sense
>(self-deadlock cannot happen, and an unlock when not lock is defined to
>return an error), so I don't think anything like that is even needed.
Doh, sorry, I meant this instead i.e. the non-recursive mutex.
(I forgot that I'd moved the non-recursive std::mutex definition to a
new file, and just edited the first thing I saw in include/std/mutex!)
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 673 bytes --]
diff --git a/libstdc++-v3/include/bits/mutex.h b/libstdc++-v3/include/bits/mutex.h
index 43f5b0b..7f88821 100644
--- a/libstdc++-v3/include/bits/mutex.h
+++ b/libstdc++-v3/include/bits/mutex.h
@@ -63,7 +63,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef __gthread_mutex_t __native_type;
#ifdef __GTHREAD_MUTEX_INIT
+# if _GLIBCXX_ASSERTIONS && defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP)
+ // Use an error-checking mutex type when assertions are enabled.
+ __native_type _M_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+# else
__native_type _M_mutex = __GTHREAD_MUTEX_INIT;
+# endif
constexpr __mutex_base() noexcept = default;
#else
next prev parent reply other threads:[~2015-09-27 10:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-07 19:04 Jonathan Wakely
2015-09-07 19:14 ` Daniel Krügler
2015-09-07 19:59 ` Jonathan Wakely
2015-09-07 20:12 ` Jonathan Wakely
2015-09-07 20:20 ` Daniel Krügler
2015-09-07 19:53 ` Florian Weimer
2015-09-07 20:10 ` Jonathan Wakely
2015-09-08 13:15 ` Michael Matz
2015-09-08 14:47 ` Jonathan Wakely
2015-09-08 15:03 ` Florian Weimer
2015-09-08 15:50 ` Jonathan Wakely
2015-09-09 16:18 ` Florian Weimer
2015-09-10 16:38 ` Martin Sebor
2015-09-10 16:39 ` Florian Weimer
2015-09-10 17:08 ` Martin Sebor
2015-09-14 10:11 ` Florian Weimer
2015-09-26 22:02 ` Jonathan Wakely
2015-09-26 22:11 ` Florian Weimer
2015-09-27 15:14 ` Jonathan Wakely [this message]
2015-09-28 14:54 ` Florian Weimer
2015-09-08 20:01 ` François Dumont
2015-09-09 14:03 ` Jonathan Wakely
2015-09-09 17:48 ` Jonathan Wakely
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=20150927102432.GM12094@redhat.com \
--to=jwakely@redhat.com \
--cc=frs.dumont@gmail.com \
--cc=fweimer@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=msebor@gmail.com \
/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).