public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "boris at kolpackov dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/101978] thread sanitizer false positive when condition variable
Date: Mon, 18 Jul 2022 11:35:35 +0000	[thread overview]
Message-ID: <bug-101978-4-4WNCc9LPPp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101978-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101978

Boris Kolpackov <boris at kolpackov dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |boris at kolpackov dot net

--- Comment #4 from Boris Kolpackov <boris at kolpackov dot net> ---
Reproduces with GCC 11.3.0 from Debian.

There is speculation on StackOverflow that links to this bug that this is
somehow causes by holding the mutex while calling notify_all(). But in our case
we get this bogus report without holding the mutex when calling notify_all().
Here is what the relevant parts in our code look like:

{
  unique_lock l (state_->mutex);
  state_->finished = true;
}

state_->condv.notify_all ();

And:

unique_lock l (state_->mutex);

if (!state_->finished &&
    !state_->condv.wait_for (l, tm, [state_] {return state_->finished;}))
  return nullopt;

Also, in our case we get two variants of this warning: as originally reported
and the second where the mutex is supposedly already destroyed (shown below).
Replacing wait_for() with wait() makes both disappear.

WARNING: ThreadSanitizer: double lock of a mutex (pid=1881)
    #0 pthread_mutex_lock
../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4240
(libtsan.so.0+0x4f30a)
    #1 __gthread_mutex_lock
/usr/include/x86_64-linux-gnu/c++/11/bits/gthr-default.h:749
(libbuild2-0.15.0-a.0.ecfa0f59dab6.so+0x624ff5)
    #2 std::mutex::lock() /usr/include/c++/11/bits/std_mutex.h:100
(libbuild2-0.15.0-a.0.ecfa0f59dab6.so+0x625146)
    #3 std::unique_lock<std::mutex>::lock()
/usr/include/c++/11/bits/unique_lock.h:139
(libbuild2-0.15.0-a.0.ecfa0f59dab6.so+0x62c701)
    #4 std::unique_lock<std::mutex>::unique_lock(std::mutex&)
/usr/include/c++/11/bits/unique_lock.h:69
(libbuild2-0.15.0-a.0.ecfa0f59dab6.so+0x62c64c)
    #5 operator()
/tmp/bootstrap/build2-toolchain-0.15-a.0/libbutl-0.15.0-a.0.20220714150118.f07a6606e44d/libbutl/builtin.ixx:56
(libbutl-0.15.0-a.0.f07a6606e44d.so+0x24d443)
    ...

  Location is heap block of size 104 at 0x7b1c00017370 allocated by thread T9:
    #0 operator new(unsigned long)
../../../../src/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x8857c)
    #1 async_impl
/tmp/bootstrap/build2-toolchain-0.15-a.0/libbutl-0.15.0-a.0.20220714150118.f07a6606e44d/libbutl/builtin.cxx:2191
(libbutl-0.15.0-a.0.f07a6606e44d.so+0x248ee8)
    #2 async_impl<butl::echo>
/tmp/bootstrap/build2-toolchain-0.15-a.0/libbutl-0.15.0-a.0.20220714150118.f07a6606e44d/libbutl/builtin.cxx:2205
(libbutl-0.15.0-a.0.f07a6606e44d.so+0x24db72)
    #3 run_pipe
/tmp/bootstrap/build2-toolchain-0.15-a.0/build2-0.15.0-a.0.20220717074539.ecfa0f59dab6/libbuild2/script/run.cxx:2160
(libbuild2-0.15.0-a.0.ecfa0f59dab6.so+0x82a1ec)
    #4 run_expr
/tmp/bootstrap/build2-toolchain-0.15-a.0/build2-0.15.0-a.0.20220717074539.ecfa0f59dab6/libbuild2/script/run.cxx:2492
(libbuild2-0.15.0-a.0.ecfa0f59dab6.so+0x82c409)
    ...

  Mutex M810501818139374456 is already destroyed.

  parent reply	other threads:[~2022-07-18 11:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 14:31 [Bug sanitizer/101978] New: thread sanitizer false positive when smart pointers ispavlick at gmail dot com
2021-08-19 16:59 ` [Bug sanitizer/101978] " ispavlick at gmail dot com
2021-08-20  7:53 ` [Bug sanitizer/101978] thread sanitizer false positive when condition variable marxin at gcc dot gnu.org
2022-02-20  6:04 ` danregister at poczta dot fm
2022-07-18 11:35 ` boris at kolpackov dot net [this message]
2022-07-28 15:36 ` lewis at sophists dot com
2022-09-23 14:52 ` jakob.weisblat at zoom dot us
2022-09-23 16:44 ` pinskia at gcc dot gnu.org
2022-09-23 16:47 ` jakob.weisblat at zoom dot us
2022-09-23 17:19 ` redi at gcc dot gnu.org
2022-09-23 18:30 ` redi 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-101978-4-4WNCc9LPPp@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).