From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 6C484384F035; Fri, 17 Feb 2023 20:33:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C484384F035 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x32b.google.com with SMTP id 12so1739837wmk.2; Fri, 17 Feb 2023 12:33:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=npgZubcaD4Y8YXojqwfPZbclYXfvybFipNYNj9w8SBU=; b=BwJLPSye8+iGu878sxKPNDKye2oc0s6VyZwtEmzUSFDBwXfiMyzjiRfFaf+MgdifWF /141cFFzEP6yCMq9TcGjz49XSaaYQ2R5+U1WbI8I2v3Wga5sfflJ3KmtGPp8Kjc7IwpS KchHU/O3iMU2i6u8XmjNLTDtHtWkzSGqRSVo8pJjfEQvSQ79X0/1JOcFmUzIRoZHyo93 8P7HbBXXDRM0Aq68I70lJQzpPeJtuZHWORb+cR6gQHhBmitUo4rOsyKuJAS5Mw9soQtO 2mKa+tb8kk2quPMSNtjexJuNfiodJp/0pQxzQH8DsRy5iTepaXiTscoK+Xy8+SQvMf8q 5ZCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=npgZubcaD4Y8YXojqwfPZbclYXfvybFipNYNj9w8SBU=; b=MPmcAuLGH+A8NAaE4Oo/IzEMoRIAcOunZn1OqXWLl5DEV/Ibbvm9GsW3SFFKVSZIuq h/WAaKed/izutxj+rdH2gXNdW5GtiOpar6dNOl6Y31EWdD4boqd+2QBR0OaUWvHLo+0k vuPNzApnaqARFeOglsv7e1BiLCgDAPt/2m5sI31u+B19KqjfCHmBqF04Z/oHbrerrHeV egmoMAQbWEljRIp2tgmtb2ivkedsVZzo5ls5tLxG0xTw7YY5dIFBc4zwCZz6SVz6MT0l 5npmYzmm63UEhhNwD6XjNr2uySPag8pLiDAVimIion83vZVRuXMDVWJEEEQo/7eorhCf HI1A== X-Gm-Message-State: AO0yUKXXFGUm4zusDN+IvD0gvXO3rrj3sBrdK3n/KaCjB4t8qy7zk27z 8NeWQ6FxALJMaMRj6LsXFiQ= X-Google-Smtp-Source: AK7set+hcPivd1tF4hLAWV/EiD4iKiCXZ4K83JFUnNkoei+BJgMD4KF3aKi24H/JUf2p8UuspxnrAA== X-Received: by 2002:a05:600c:244e:b0:3e0:185:e935 with SMTP id 14-20020a05600c244e00b003e00185e935mr2175457wmr.36.1676665993100; Fri, 17 Feb 2023 12:33:13 -0800 (PST) Received: from ?IPV6:2a01:e0a:1dc:b1c0:f487:3119:5f72:2163? ([2a01:e0a:1dc:b1c0:f487:3119:5f72:2163]) by smtp.googlemail.com with ESMTPSA id x8-20020a05600c21c800b003dc434b39c7sm2429504wmj.0.2023.02.17.12.33.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Feb 2023 12:33:12 -0800 (PST) Message-ID: Date: Fri, 17 Feb 2023 21:33:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH] [libstdc++] ensure mutex_pool survives _Safe_sequence_base To: Alexandre Oliva , gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org References: Content-Language: fr From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 17/02/23 09:01, Alexandre Oliva via Libstdc++ wrote: > On Feb 17, 2023, Alexandre Oliva wrote: > >> On vxworks, after destroying the semaphore used to implement a mutex, >> __gthread_mutex_lock fails and __gnu_cxx::__mutex::lock calls >> __throw_concurrence_lock_error. Nothing ensures the mutex_pool >> mutexes survive init-once objects containing _Safe_sequence_base. If >> such an object completes construction before mutex_pool >> initialization, it will be registered for atexit destruction after the >> mutex_pool mutexes, so the _M_detach_all() call in the >> _Safe_sequence_base dtor will use already-destructed mutexes, and >> basic_string/requirements/citerators_cc fails calling terminate. > Here's an alternative approach, with zero runtime overhead. Negative > overhead, if you count the time it would have taken to destruct the > mutex pool :-) But it fails to destruct them, which is presumably of no > consequence. > > [libstdc++] do not destruct mutex_pool mutexes > > [Copy of the paragraph quoted above omitted here] > > This patch fixes this problem by ensuring the mutex pool mutexes are > constructed on demand, on a statically-allocated buffer, but never > destructed. > > Regstrapped on x86_64-linux-gnu. > Tested on arm-vxworks7 (gcc-12) and arm-eabi (trunk). Ok to install? > > for libstdc++-v3/ChangeLog > > * src/c++11/shared_ptr.cc (__gnu_internal::get_mutex): > Avoid destruction of the mutex pool. > --- > libstdc++-v3/src/c++11/shared_ptr.cc | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/libstdc++-v3/src/c++11/shared_ptr.cc b/libstdc++-v3/src/c++11/shared_ptr.cc > index bc70134359c87..74e879e582896 100644 > --- a/libstdc++-v3/src/c++11/shared_ptr.cc > +++ b/libstdc++-v3/src/c++11/shared_ptr.cc > @@ -36,7 +36,11 @@ namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden) > { > // increase alignment to put each lock on a separate cache line > struct alignas(64) M : __gnu_cxx::__mutex { }; > - static M m[mask + 1]; > + // Use a static buffer, so that the mutexes are not destructed > + // before potential users (or at all) I guess you meant 'before potential use' > + static __attribute__ ((aligned(__alignof__(M)))) > + char buffer[(sizeof (M)) * (mask + 1)]; > + static M *m = new (buffer) M[mask + 1]; > return m[i]; > } > } >