From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C4689384B011; Mon, 29 Mar 2021 20:03:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4689384B011 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/99537] Wrong memory_order used in stop_token ref-counting Date: Mon, 29 Mar 2021 20:03:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org 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: 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, 29 Mar 2021 20:03:27 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99537 --- Comment #3 from CVS Commits --- The releases/gcc-10 branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:ad9ae82ed1c33e1803f33bb367b0b4c9ee2e3e63 commit r10-9594-gad9ae82ed1c33e1803f33bb367b0b4c9ee2e3e63 Author: Jonathan Wakely Date: Thu Mar 11 16:44:57 2021 +0000 libstdc++: Use acq_rel memory ordering [PR 99537] As Lewis Baker wrote in the PR: > The 'fetch_sub()' operation in _M_release_ownership() should be using > memory_order::acq_rel instead of memory_order::release. The use of > 'release' only is insufficient as it does not synchronise with any > corresponding 'acquire' operation. > With the current implementation, it's possible that a prior write to > one of the _M_value or _M_head data-members by a thread releasing the > second-to-last reference might not be visible to another thread that > releases the last reference and frees the memory, resulting in > potential write to freed memory. This simply changes the memory order to acq_rel as suggested. libstdc++-v3/ChangeLog: PR libstdc++/99537 * include/std/stop_token (_Stop_state_t::_M_release_ownership): Use acq_rel memory ordering. (cherry picked from commit 15825b17cf3fbf28181c51fe94a2898f448f915c)=