On 03/14/2011 10:41 AM, Andrew Stitcher wrote:
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).


In general end() is not thread safe or constant. If you are using plain pointers as iterators over a C array, then end() is a pointer to one place after the last element of the array and changes if the array size changes. Probably many std container iterator implementations do something similar to keep the arithmetic simple.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscr...@qpid.apache.org

Reply via email to