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 mode performance patch


On 11/07/2010 04:36 PM, Paolo Carlini wrote:
On 11/04/2010 09:27 PM, François Dumont wrote:
Moreover I forget to signal that in _Safe_sequence_base::_M_swap I had
to lock both sequences mutex. So I hope that the scope_lock are
reentrant cause for the moment both sequences might be associated to
the same mutex instance. I hope I haven't been simply lucky during tests.
Before we go ahead with the patch could you please explain the above
issue in better detail? Maybe Jon could also help here.

As announced I prefer to use a consistent approach in the debug mode locks, I always lock the sequence mutex as soon as I start modifying the lists of safe iterators within it. In swap we touch to both sequences' lists at the same time so we have to lock both mutexes. However I realized that if you have a thread iterating over a sequence while you swap it in an other thread it has chances to fail in debug mode because when the thread iterating will check for sequence end it might do so at a moment where both safe iterators has not been assigned to the same safe sequence resulting in an invalid comparison of iterators from different sequences. Now the question is whether this kind of concurrent usage should be considered as valid ? If so the patch will have to be reviewed cause the only covered use case is concurrent read only operations. I really hesitated locking in write operations but I considered that impacting different part of the sequence could still be correctly handle. In the case of the swap operation that impact the whole sequence maybe we could completely remove the locks.

Also, I would recommend moving the two large _Safe_sequence functions to
a new safe_sequence.tcc (please stylistically double check the positions
of the open curly brackets in _M_transfer_from_if and elsewhere).
Ok

François


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