473,591 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

atexit problems on statics inside mixed assembly after moving to VS2005

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::CShadowObj ects::~CShadowO bjects() Line 31 C++
ExecutableD.exe !`GE::CShadowOb jects::GetInsta nce'::`2'::`dyn amic
atexit destructor for 'g_ShadowObject s''() + 0xd bytes C++

second automatic destruction (call stack):
ExecutableD.exe !GE::CShadowObj ects::~CShadowO bjects() Line 31 C++
ExecutableD.exe !`GE::CShadowOb jects::GetInsta nce'::`2'::`dyn amic
atexit destructor for 'g_ShadowObject s''() + 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/mi...5&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 /
clr:oldSyntax and Managed Extensions for C++.

This page ( http://msdn2.microsoft.com/en-us/lib...68(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 /clr:oldSyntax ?

We have a number of native C++ libs (no clr) that are then linked into
an executable project built with /clr:oldSyntax. 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

Jun 21 '07 #1
20 5995
Aek wrote:
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?
It could be. Shouldn't be, but it's definitely the case that /clr was
tested a lot more carefully than /clr:oldSyntax for VS2005.
>
Any other suggestions?
Contact PSS. It sounds like you're looking at something complex and subtle
that may require inside knowledge to fully diagnose and understand.

-cd
Jun 21 '07 #2

"Aek" <ae*********@gm ail.comwrote in message
news:11******** **************@ x35g2000prf.goo glegroups.com.. .
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
Are you doing the atexit registration in code, or the compiler is doing it
automatically?
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::CShadowObj ects::~CShadowO bjects() Line 31 C++
ExecutableD.exe !`GE::CShadowOb jects::GetInsta nce'::`2'::`dyn amic
atexit destructor for 'g_ShadowObject s''() + 0xd bytes C++

second automatic destruction (call stack):
ExecutableD.exe !GE::CShadowObj ects::~CShadowO bjects() Line 31 C++
ExecutableD.exe !`GE::CShadowOb jects::GetInsta nce'::`2'::`dyn amic
atexit destructor for 'g_ShadowObject s''() + 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/mi...5&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 /
clr:oldSyntax and Managed Extensions for C++.

This page ( http://msdn2.microsoft.com/en-us/lib...68(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 /clr:oldSyntax ?

We have a number of native C++ libs (no clr) that are then linked into
an executable project built with /clr:oldSyntax. 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

Jun 21 '07 #3
Aek
On Jun 22, 1:27 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
"Aek" <aek.muld...@gm ail.comwrote in message

news:11******** **************@ x35g2000prf.goo glegroups.com.. .
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.
The compiler is generating the atexit registration automatically.

Thanks
Josh
Jun 22 '07 #4

"Aek" <ae*********@gm ail.comwrote in message
news:11******** **************@ j4g2000prf.goog legroups.com...
On Jun 22, 1:27 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
>"Aek" <aek.muld...@gm ail.comwrote in message

news:11******* *************** @x35g2000prf.go oglegroups.com. ..
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.

The compiler is generating the atexit registration automatically.
Can you place a breakpoint on atexit and see if the cleanup code is
registered twice?

Are there multiple static objects in the same function, of which it would be
possible that only some are fully constructed due to exceptions?
>
Thanks
Josh

Jun 22 '07 #5
Aek
On Jun 22, 1:27 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
"Aek" <aek.muld...@gm ail.comwrote in message

news:11******** **************@ x35g2000prf.goo glegroups.com.. .
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.
The atexit registration is automatically generated by the compiler.
After some experimenting yesterday, I found that if I rebuild one of
my problematic native C++ libs with the /clr:oldSyntax flag then the
problems with the statics in that lib are resolved. Problem is though
that one of the native libs is a graphics engine and it goes from real
time to slower than powerpoint with /clr enabled in the lib, so I
would like to leave the native C++ libs without clr.

Thankyou
Josh

Jun 22 '07 #6
Aek
On Jun 22, 10:44 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
"Aek" <aek.muld...@gm ail.comwrote in message

news:11******** **************@ j4g2000prf.goog legroups.com...
On Jun 22, 1:27 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
"Aek" <aek.muld...@gm ail.comwrote in message
>news:11******* *************** @x35g2000prf.go oglegroups.com. ..
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.
The compiler is generating the atexit registration automatically.

Can you place a breakpoint on atexit and see if the cleanup code is
registered twice?
Yes I can, I just need to find where it is. Ill give it a go today.
Are there multiple static objects in the same function, of which it would be
possible that only some are fully constructed due to exceptions?
No, generally the problem is seen in functions that only have a single
static in the function. There seems to be the same problem with all
locally declared statics in native C++ libs (not just 1 case), so I do
not believe exceptions are occuring causing only some statics to be
fully constructed.

Thanks for your help so far.
Josh

Jun 22 '07 #7

"Aek" <ae*********@gm ail.comwrote in message
news:11******** **************@ e9g2000prf.goog legroups.com...
On Jun 22, 10:44 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
>"Aek" <aek.muld...@gm ail.comwrote in message

news:11******* *************** @j4g2000prf.goo glegroups.com.. .
On Jun 22, 1:27 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
"Aek" <aek.muld...@gm ail.comwrote in message
>>news:11****** *************** *@x35g2000prf.g ooglegroups.com ...
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.
The compiler is generating the atexit registration automatically.

Can you place a breakpoint on atexit and see if the cleanup code is
registered twice?

Yes I can, I just need to find where it is. Ill give it a go today.
>Are there multiple static objects in the same function, of which it would
be
possible that only some are fully constructed due to exceptions?

No, generally the problem is seen in functions that only have a single
static in the function. There seems to be the same problem with all
locally declared statics in native C++ libs (not just 1 case), so I do
not believe exceptions are occuring causing only some statics to be
fully constructed.
Ok, that was the only reason I could think of for having more than one
cleanup handler executed for the same function.

Oh... is there any possibility that the singleton is accessed from other
atexit handlers/static destructors?
>
Thanks for your help so far.
Josh
Jun 22 '07 #8

"Aek" <ae*********@gm ail.comwrote in message
news:11******** *************@i 38g2000prf.goog legroups.com...
On Jun 22, 1:27 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
>"Aek" <aek.muld...@gm ail.comwrote in message

news:11******* *************** @x35g2000prf.go oglegroups.com. ..
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.

The atexit registration is automatically generated by the compiler.
After some experimenting yesterday, I found that if I rebuild one of
my problematic native C++ libs with the /clr:oldSyntax flag then the
problems with the statics in that lib are resolved. Problem is though
that one of the native libs is a graphics engine and it goes from real
time to slower than powerpoint with /clr enabled in the lib, so I
would like to leave the native C++ libs without clr.
Can you open your assembly with .NET Reflector and make sure that the
SuppressUnmanag edCodeSecurityA ttribute is applied?
>
Thankyou
Josh
Jun 22 '07 #9
Aek
On Jun 22, 10:44 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
Can you place a breakpoint on atexit and see if the cleanup code is
registered twice?
I stepped through the local static creation and can confirm that the
atexit code for the local static is _not_ being called twice, but the
destructor is called twice on the same object.

-Josh

Jun 25 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
895
by: Paul | last post by:
Given test.exe - C++, non-mfc, non-clr bar.dll - C++, non-mfc, non-cr foo.dll - C++, non-mfc, clr, some managed and some unmanaged If I run tests from a local drive, say c:\bin, I can loadlibray on bar.dll and foo.dll w/ no problems. If I run tests from a share, say p:\remotebin, I see problems:
3
3663
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following runtime error, " Attempting to call into managed code without transitioning out first. Do not attempt to run managed code inside low-level native extensibility points, such as the vectored exception handler, since doing so can cause corruption...
0
1367
by: DPR | last post by:
Hi, I've recognized that a mixed assembly with unmanaged exports and an unmanaged "DllMain" can't be unloaded from a (unmanaged) process, even if it's no longer needed and the (unmanaged) process calls the "FreeLibrary" function. I couldn't find any documentation for this special restriction ! So isn't there any possibility to unload a mixed assembly manually from a unmanaged process once it has been loaded without killing that process ?
3
3943
by: dfranzen | last post by:
Hi *, I'm in the process of porting an ANSI C++ project from a UNIX platform to .NET. After "getting rid of" some platform-specific stuff I managed to compile the first two libraries into mixed assemlies (DLLs) using MSVC8 (VS2005) with the /clr option. However, I get hundreds of linker errors (mostly LNK2028) because assembly B uses native types defined in assembly A. I could easily get rid of the problem by #including the original source...
2
1263
by: MC-Advantica | last post by:
I have a managed C++ based assembly referencing a bunch of unmanaged DLLs. I strongly name the the mixed assembly, and place it in the GAC. I write a VB client and reference the managed assembly: 1) What does the managed assembly look at to decide where to look for the unmanaged DLL dependencies? 2) Why do I run into difficulties running clients EXEs (e.g., VB) against the GAC based assembly?
1
2682
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I have an VC++ MFC Win32 application that isn't working correctly when I build it with VS2005. The problem seems to be in some ADO ActiveX controls that came with VS6 and are now out of support. So, I have decided to solve the problem by using a mixed assembly: Most of the program will be my MFC - based code (unmanaged), but I will implement one dialog box as managed code. In my original MFC app, this dialog box contains the problem ActiveX...
7
4792
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I'm new to working with mixed assemblies. All of my previous experience has been with VC++/MFC in native, unmanaged applications. When I create a mixed assembly in which one or more of the files compiles with /clr the instructions say that I need to change the switch for Debug information format from Program Database for Edit & Continue to disabled. At runtime I find that I am not able to set breakpoints in the managed code, nor trace...
0
886
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I have a mixed assembly. Visual C++/MFC and a .NET C# Windows Form User Control to be used in an MFC dialog box. Most of the modules in the Visual C++/MFC part of the project are native/unmanaged. Two modules are managed (compiled with /clr). The program seems to run correctly. However, when I do File...Exit, I get an error message saying 'FatalExecutionEngineError' has detected a problem. When I debug, I can see that the error is...
1
1639
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
VS2005 - VC++/MFC: most modules compiled as native. Two modules compiled as /clr (managed). One of these two modules uses a .NET C# Windows form User control in an MFC dialog box. The program seems to run fine, but crashes when I exit. The same crash occurs even if I immediately exit when the program window opens. I have reproduced the problem on two development systems. While the final
0
7934
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8362
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8225
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6639
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.