This is the mail archive of the
pthreads-win32@sourceware.org
mailing list for the pthreas-win32 project.
pthread_exit and STL problems
- From: Stefan Eilemann <eilemann at gmail dot com>
- To: Pthreads-Win32 list <pthreads-win32 at sourceware dot org>
- Date: Tue, 30 Jan 2007 10:18:59 +0100
- Subject: pthread_exit and STL problems
Hi,
I am tracking down a problem in my code using VC++ 8.0 and
pthreads-win32 2.8.0. My hope is that somebody on the list has
seen (and solved) this problem.
In my code I am removing elements from a std::vector<>, which
works fine until the first pthread has exited. After this point,
I am getting a crash in the debug version when erasing an element
from the vector:
vector<Object*>::iterator iter = find( objects.begin(),
objects.end(),
object );
if( iter == objects.end( ))
return;
objects.erase( iter );
This is the call stack:
Equalizer.dll!std::vector<eqNet::Object
*,std::allocator<eqNet::Object *> >::_Orphan_range(eqNet::Object * *
_First=0x0038c830, eqNet::Object * * _Last=0x0038c834) Line 1233 +
0x5 bytes
Equalizer.dll!std::vector<eqNet::Object
*,std::allocator<eqNet::Object *> >::erase
(std::_Vector_iterator<eqNet::Object *,std::allocator<eqNet::Object
*> > _Where=0x00395fe0 {_initData={...} _frameData={...}
_displayLists={...} }) Line 990
Equalizer.dll!eqNet::Session::removeRegisteredObject(eqNet::Object *
object=0x00395fe0, eqNet::Object::SharePolicy policy=SHARE_NODE)
Line 304 + 0x29 bytes
Equalizer.dll!eq::Node::_cmdDestroyPipe(eqNet::Command & command=
{...}) Line 134 C++
The code in question seems to invalidate all iterators of the vector.
The crash happens because _Pnext gets an invalid pointer after some
iterations:
#if _HAS_ITERATOR_DEBUGGING
void _Orphan_range(pointer _First, pointer _Last) const
{ // orphan iterators within specified (inclusive) range
_Lockit _Lock(_LOCK_DEBUG);
const_iterator **_Pnext = (const_iterator **)&this->_Myfirstiter;
while (*_Pnext != 0)
if ((*_Pnext)->_Myptr < _First || _Last < (*_Pnext)->_Myptr)
_Pnext = (const_iterator **)&(*_Pnext)->_Mynextiter;
else
{ // orphan the iterator
(*_Pnext)->_Mycont = 0;
*_Pnext = (const_iterator *)(*_Pnext)->_Mynextiter;
}
}
#endif /* _HAS_ITERATOR_DEBUGGING */
Again - this code is called numerous time before without problem. The
first time the crash happens is when a pthread has been exit'ed, and
the calling thread just called pthread_join() shortly before the call
above. I am linking against the multithreaded debug runtime.
Has anybody seen this already? Does the thread exit code cleanup/
interfere
with the VC8 STL implementation? Any hints?
Cheers,
Stefan.
--
http://www.equalizergraphics.com
http://www.linkedin.com/in/eilemann