Re: Testing if an iterator is invalid ?
On Jul 20, 1:12 am, khalid...@gmail.com wrote:
I'm writing a multi-threaded application where one thread waits for a
certain std::set element to be deleted by another thread.
The waiting thread already has an iterator pointing at the element
that has to be deleted. After the other thread deletes this element,
the iterator will become invalid.
Is there a way to know if a certain iterator is invalid ?
No.
The suggestions of assigning NULL to the iterator (which
probably won't compile) or assigning something through it (which
is undefined behavior, and will likely lead to a core dump) are
just bullshit. Ian is the only one who really got this right:
you must use a special synchronization object, supported by your
OS. Under Unix, pthread_cond_t; under Windows, I don't know.
Or better yet, use the conditional object in Boost threads.
Without external synchronization by the OS (or perhaps some
platform specific assembler code), you have undefined behavior.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34