From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 8B7AC3850423; Mon, 29 Mar 2021 20:03:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B7AC3850423 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-9594] libstdc++: Use acq_rel memory ordering [PR 99537] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 6e5f662f1dd6e3d1a79e194c118c295b897fc7ef X-Git-Newrev: ad9ae82ed1c33e1803f33bb367b0b4c9ee2e3e63 Message-Id: <20210329200326.8B7AC3850423@sourceware.org> Date: Mon, 29 Mar 2021 20:03:26 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Mar 2021 20:03:26 -0000 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) Diff: --- libstdc++-v3/include/std/stop_token | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/stop_token b/libstdc++-v3/include/std/stop_token index 80f50ea83ca..34b613e7c1a 100644 --- a/libstdc++-v3/include/std/stop_token +++ b/libstdc++-v3/include/std/stop_token @@ -191,7 +191,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void _M_release_ownership() noexcept { - if (_M_owners.fetch_sub(1, memory_order::release) == 1) + if (_M_owners.fetch_sub(1, memory_order::acq_rel) == 1) delete this; }