A
Aek
We recently moved our large codebase over from VS7 to 8 and found that
we now get access violations in atexit calls at shutdown when
debugging the application in VS2005.
This occurs in static members / singletons (especially meyer type
singletons) which use locally declared static variables. These
variables are normally cleaned up automatically at shutdown of the
application by registering with the atexit. I break point the
destructor on a problem singleton class and notice that the destructor
of this static is called automatically *twice* with atexit. The second
call will cause the crash.
first automatic destruction (call stack):
ExecutableD.exe!GE::CShadowObjects::~CShadowObjects() Line 31 C++
ExecutableD.exe!`GE::CShadowObjects::GetInstance'::`2'::`dynamic
atexit destructor for 'g_ShadowObjects''() + 0xd bytes C++
second automatic destruction (call stack):
ExecutableD.exe!GE::CShadowObjects::~CShadowObjects() Line 31 C++
ExecutableD.exe!`GE::CShadowObjects::GetInstance'::`2'::`dynamic
atexit destructor for 'g_ShadowObjects''() + 0xd bytes C++
We notice that this singleton is implemented using a meyers singleton
that has a local static in the GetInstance() method and no specific
destroy call is needed. When I change the singleton to one that
contains a pointer to class and then call new in the GetInstance, then
it is fine. However I dont want to change tonnes of seemingly valid
code just to work around this crash.
We have no visible problems when we are running the application
outside of the IDE.
I believe it is a similar problem to this one described here:
http://groups.google.com.au/group/m...exit+crashes+static+local+VS2005&rnum=3&hl=en
I think that perhaps it has something to do with the mix managed /
unmanaged code or perhaps it has something to do with using /
clrldSyntax and Managed Extensions for C++.
This page ( http://msdn2.microsoft.com/en-us/library/ms173268(VS.80).aspx
) suggests that the /clr option will provide support for "static
initialization of C++ variables in mixed images". Is this also true
then for /clrldSyntax ?
We have a number of native C++ libs (no clr) that are then linked into
an executable project built with /clrldSyntax. The executable
project contains Managed Extension C++ (hence the need for the
oldSyntax flag)
Ideally we will eventually get rid of Managed Extensions for C++ and
port to C++/CLI.
My main question is:
Could use of oldSyntax and Managed Extensions be a cause of the atexit
problems with static variables in a mixed assembly?
Any other suggestions?
Thankyou for your time
Josh
we now get access violations in atexit calls at shutdown when
debugging the application in VS2005.
This occurs in static members / singletons (especially meyer type
singletons) which use locally declared static variables. These
variables are normally cleaned up automatically at shutdown of the
application by registering with the atexit. I break point the
destructor on a problem singleton class and notice that the destructor
of this static is called automatically *twice* with atexit. The second
call will cause the crash.
first automatic destruction (call stack):
ExecutableD.exe!GE::CShadowObjects::~CShadowObjects() Line 31 C++
ExecutableD.exe!`GE::CShadowObjects::GetInstance'::`2'::`dynamic
atexit destructor for 'g_ShadowObjects''() + 0xd bytes C++
second automatic destruction (call stack):
ExecutableD.exe!GE::CShadowObjects::~CShadowObjects() Line 31 C++
ExecutableD.exe!`GE::CShadowObjects::GetInstance'::`2'::`dynamic
atexit destructor for 'g_ShadowObjects''() + 0xd bytes C++
We notice that this singleton is implemented using a meyers singleton
that has a local static in the GetInstance() method and no specific
destroy call is needed. When I change the singleton to one that
contains a pointer to class and then call new in the GetInstance, then
it is fine. However I dont want to change tonnes of seemingly valid
code just to work around this crash.
We have no visible problems when we are running the application
outside of the IDE.
I believe it is a similar problem to this one described here:
http://groups.google.com.au/group/m...exit+crashes+static+local+VS2005&rnum=3&hl=en
I think that perhaps it has something to do with the mix managed /
unmanaged code or perhaps it has something to do with using /
clrldSyntax and Managed Extensions for C++.
This page ( http://msdn2.microsoft.com/en-us/library/ms173268(VS.80).aspx
) suggests that the /clr option will provide support for "static
initialization of C++ variables in mixed images". Is this also true
then for /clrldSyntax ?
We have a number of native C++ libs (no clr) that are then linked into
an executable project built with /clrldSyntax. The executable
project contains Managed Extension C++ (hence the need for the
oldSyntax flag)
Ideally we will eventually get rid of Managed Extensions for C++ and
port to C++/CLI.
My main question is:
Could use of oldSyntax and Managed Extensions be a cause of the atexit
problems with static variables in a mixed assembly?
Any other suggestions?
Thankyou for your time
Josh