This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: debug container mutex association


On 29/12/2017 17:09, Andreas Schwab wrote:
On Sep 19 2016, François Dumont<frs.dumont@gmail.com>  wrote:

+
+class container : public __gnu_debug::_Safe_sequence<container>
+{
+public:
+  __gnu_cxx::__mutex&
+  get_mutex()
+  { return this->_M_get_mutex(); }
+};
+
+int
+main()
+{
+  std::set<__gnu_cxx::__mutex*> mutexes;
+  container conts[17];
+
+  for (int i = 0; i != 16; ++i)
+    VERIFY( mutexes.insert(&conts[i].get_mutex()).second );
There will be less than 16 unique mutexes, if sizeof(container) has more
trailing zero bits than alignof(__gnu_debug::vector<int>).

Could you elaborate a little bit ? Is this test failing on your target ?

AFAIK all libstdc++ containers have the same memory alignement so the get_safe_base_mutex in debug.cc will always associate a different mutex to the 16 containers relying in a continuous memory area.

I have instrumented the test to display each container address and its associated mutex index like computed in get_safe_base_mutex and got:
 Cont #0: 0x7ffd4b14e600 index 0
 Cont #1: 0x7ffd4b14e618 index 3
 Cont #2: 0x7ffd4b14e630 index 6
 Cont #3: 0x7ffd4b14e648 index 9
 Cont #4: 0x7ffd4b14e660 index 12
 Cont #5: 0x7ffd4b14e678 index 15
 Cont #6: 0x7ffd4b14e690 index 2
 Cont #7: 0x7ffd4b14e6a8 index 5
 Cont #8: 0x7ffd4b14e6c0 index 8
 Cont #9: 0x7ffd4b14e6d8 index 11
 Cont #10: 0x7ffd4b14e6f0 index 14
 Cont #11: 0x7ffd4b14e708 index 1
 Cont #12: 0x7ffd4b14e720 index 4
 Cont #13: 0x7ffd4b14e738 index 7
 Cont #14: 0x7ffd4b14e750 index 10
 Cont #15: 0x7ffd4b14e768 index 13
 Cont #16: 0x7ffd4b14e780 index 0

François


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]