https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- Patch for stage 1: --- a/libstdc++-v3/src/c++11/shared_ptr.cc +++ b/libstdc++-v3/src/c++11/shared_ptr.cc @@ -28,6 +28,11 @@ namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden) { + namespace + { + alignas(64) unsigned char __mutex_storage[64 * (mask + 1)]; + } + /* Returns different instances of __mutex depending on the passed index * in order to limit contention. */ @@ -36,7 +41,7 @@ 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]; + static M* m = ::new(__mutex_storage) M[mask + 1]; return m[i]; } }