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.

Reply via email to