Re: Delete a list item from a separate thread safe?
On Mon, 28 Apr 2008 18:53:25 +0200 (CEST), Joe Greer
<jgreer@doubletake.com> wrote:
But does this also happen in case of addition of a new item from a
separate thread to the list. Will this also cause invalidation of the
iterators ??
No, new items won't have iterators etc referring to them, so they can't be
invalidated. No other iterators will be invalidated either by an insertion
of a new item.
During the list update, the list is in an indeterminate state, and trying
to modify iterators to existing items may not work. For example, a list
iterator may contain a pointer to a list item, and the item's prev/next
fields may be changing during the update. So while the iterator isn't
"invalidated" by the update, it may be invalid for some operations /during/
the update, hence my advice to synchronize if iterators are used to iterate
in a thread X while a thread Y is modifying the list. Thus, unless you use
the iterator merely for dereferencing (in which case you might as well just
use a pointer or reference), you need to synchronize.
--
Doug Harrison
Visual C++ MVP