From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1423D3858C51; Mon, 18 Jul 2022 11:35:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1423D3858C51 From: "boris at kolpackov dot net" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: boris at kolpackov dot net X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2022 11:35:36 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101978 Boris Kolpackov changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |boris at kolpackov dot net --- Comment #4 from Boris Kolpackov --- 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 =3D 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 report= ed 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=3D1881) #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::lock() /usr/include/c++/11/bits/unique_lock.h:139 (libbuild2-0.15.0-a.0.ecfa0f59dab6.so+0x62c701) #4 std::unique_lock::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+0x88= 57c) #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 /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.e= cfa0f59dab6/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.e= cfa0f59dab6/libbuild2/script/run.cxx:2492 (libbuild2-0.15.0-a.0.ecfa0f59dab6.so+0x82c409) ... Mutex M810501818139374456 is already destroyed.=