public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Stefan Eilemann <eilemann@gmail.com>
To: Pthreads-Win32 list <pthreads-win32@sourceware.org>
Subject: pthread_exit and STL problems
Date: Tue, 30 Jan 2007 09:20:00 -0000	[thread overview]
Message-ID: <3D7E7834-79B3-4C11-BA29-DBF2821B8B6B@gmail.com> (raw)

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



             reply	other threads:[~2007-01-30  9:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-30  9:20 Stefan Eilemann [this message]
     [not found] ` <45BFD127.6040609@homemail.com.au>
2007-01-31  9:02   ` Stefan Eilemann
2007-01-31 13:54     ` Streithorst, Kip
     [not found]     ` <45C0A0B5.6040306@homemail.com.au>
     [not found]       ` <A75AD195-4E38-4A02-8979-A3EC3C568FB2@gmail.com>
     [not found]         ` <45C1DFB1.6010508@homemail.com.au>
2007-02-02  9:11           ` Stefan Eilemann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D7E7834-79B3-4C11-BA29-DBF2821B8B6B@gmail.com \
    --to=eilemann@gmail.com \
    --cc=pthreads-win32@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).