[Bug libstdc++/71312] mutexes for shared_ptr atomics should be padded to cacheline size
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 11 21:45:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71312
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
A slightly simpler fix:
--- a/libstdc++-v3/src/c++11/shared_ptr.cc
+++ b/libstdc++-v3/src/c++11/shared_ptr.cc
@@ -34,7 +34,9 @@ namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden)
__gnu_cxx::__mutex&
get_mutex(unsigned char i)
{
- static __gnu_cxx::__mutex m[mask + 1];
+ // increase alignment to ensure each lock is on a separate cache line
+ struct alignas(64) M : __gnu_cxx::__mutex { };
+ static M m[mask + 1];
return m[i];
}
}
More information about the Gcc-bugs
mailing list