On Mon, 2011-03-14 at 10:12 -0400, Carl Trieloff wrote:
> On 03/14/2011 10:07 AM, Gordon Sim wrote:
> > Its the iterator that is the issue, not the smart pointer that it 
> > points to. You test (it == bindingCache.end()) outside the lock and 
> > that is not safe. 
> 
> FYI -- .end()  function is independent of the validity of the iterator. 
> 'it' will either == the const of end, or ref the smart pointer which
> is then safe, even if cleared. I maintain it it safe.

It's not clear to me from a quick squint at the standard whether
map::end is required to be a constant valid irrespective of further
changes to a map in a different thread so I can't say for sure who is
correct here. However changing the code to use a temporary bool to hold
the value of it==bindCache.end() inside the mutex makes the code
uncontroversial and the compiler will optimise it away if it truly is a
constant (well if it's defined in the header).

Andrew



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to