aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstdc++-v3/src/c++11/shared_ptr.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/libstdc++-v3/src/c++11/shared_ptr.cc b/libstdc++-v3/src/c++11/shared_ptr.cc
index bc70134..74e879e 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];
}
}