public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] [libstdc++] do not destruct mutex_pool mutexes
@ 2023-02-16 11:13 Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2023-02-16 11:13 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:f7fc3cbf626dd41ba4fe1cfba8a23a1236f89e4e

commit f7fc3cbf626dd41ba4fe1cfba8a23a1236f89e4e
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Thu Feb 16 07:45:43 2023 -0300

    [libstdc++] do not destruct mutex_pool mutexes
    
    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.
    
    This patch fixes this problem by ensuring the mutex pool mutexes are
    constructed on demand, on a statically-allocated buffer, but never
    destructed.
    
    
    for  libstdc++-v3/ChangeLog
    
            * src/c++11/shared_ptr.cc (__gnu_internal::get_mutex):
            Avoid destruction of the mutex pool.

Diff:
---
 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 bc70134359c..74e879e5828 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)
+    static __attribute__ ((aligned(__alignof__(M))))
+      char buffer[(sizeof (M)) * (mask + 1)];
+    static M *m = new (buffer) M[mask + 1];
     return m[i];
   }
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/users/aoliva/heads/testme)] [libstdc++] do not destruct mutex_pool mutexes
@ 2023-02-22 14:49 Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2023-02-22 14:49 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:edc86db529152e5d9a0c49764c3bcae81fda3292

commit edc86db529152e5d9a0c49764c3bcae81fda3292
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Thu Feb 16 07:45:43 2023 -0300

    [libstdc++] do not destruct mutex_pool mutexes
    
    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.
    
    This patch fixes this problem by ensuring the mutex pool mutexes are
    constructed on demand, on a statically-allocated buffer, but never
    destructed.
    
    
    for  libstdc++-v3/ChangeLog
    
            * src/c++11/shared_ptr.cc (__gnu_internal::get_mutex):
            Avoid destruction of the mutex pool.

Diff:
---
 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 bc70134359c..74e879e5828 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)
+    static __attribute__ ((aligned(__alignof__(M))))
+      char buffer[(sizeof (M)) * (mask + 1)];
+    static M *m = new (buffer) M[mask + 1];
     return m[i];
   }
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-22 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-16 11:13 [gcc(refs/users/aoliva/heads/testme)] [libstdc++] do not destruct mutex_pool mutexes Alexandre Oliva
2023-02-22 14:49 Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).