473,802 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static msclr::auto_gcr oot managed variables and the linker lock error

Hi,

I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.

Feb 12 '07 #1
4 2356

"DaTurk" <mm******@hotma il.comwrote in message
news:11******** **************@ k78g2000cwa.goo glegroups.com.. .
Hi,

I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.
It's the "loader lock", not "linker lock" that will bite you with static
native variables in mixed assemblies. Essentially, when static variables
are initialized, the managed runtime typically isn't started yet, so you
can't create managed objects. Destruction has the same issues, static
variables last until the very end, when the managed runtime has typically
shutdown.

I think you might be able to work around with a pointer to gcroot and lazy
initialization. And you'll have to explicitly delete the gcroot object to
get cleanup right.

And don't even think of using a native class instance declared as a global
to perform your init and cleanup, that's the same problem all over again,
although the linker probably wouldn't recognize it.
Feb 13 '07 #2
On Feb 12, 7:12 pm, "Ben Voigt" <r...@nospam.no spamwrote:
"DaTurk" <mmagd...@hotma il.comwrote in message

news:11******** **************@ k78g2000cwa.goo glegroups.com.. .
Hi,
I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.

It's the "loader lock", not "linker lock" that will bite you with static
native variables in mixed assemblies. Essentially, when static variables
are initialized, the managed runtime typically isn't started yet, so you
can't create managed objects. Destruction has the same issues, static
variables last until the very end, when the managed runtime has typically
shutdown.

I think you might be able to work around with a pointer to gcroot and lazy
initialization. And you'll have to explicitly delete the gcroot object to
get cleanup right.

And don't even think of using a native class instance declared as a global
to perform your init and cleanup, that's the same problem all over again,
although the linker probably wouldn't recognize it.
I'm not entirely sure what lazy init is, could you elaborate please?

Feb 13 '07 #3

"DaTurk" <mm******@hotma il.comwrote in message
news:11******** **************@ m58g2000cwm.goo glegroups.com.. .
On Feb 12, 7:12 pm, "Ben Voigt" <r...@nospam.no spamwrote:
>"DaTurk" <mmagd...@hotma il.comwrote in message

news:11******* *************** @k78g2000cwa.go oglegroups.com. ..
Hi,
I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.

It's the "loader lock", not "linker lock" that will bite you with static
native variables in mixed assemblies. Essentially, when static variables
are initialized, the managed runtime typically isn't started yet, so you
can't create managed objects. Destruction has the same issues, static
variables last until the very end, when the managed runtime has typically
shutdown.

I think you might be able to work around with a pointer to gcroot and
lazy
initialization . And you'll have to explicitly delete the gcroot object
to
get cleanup right.

And don't even think of using a native class instance declared as a
global
to perform your init and cleanup, that's the same problem all over again,
although the linker probably wouldn't recognize it.

I'm not entirely sure what lazy init is, could you elaborate please?
Just that initialization waits until the first time you use it, maybe
involving a check for NULL. Writing an explicit initialization function
called from a managed type initializer (also called static constructor or
..cctor) also works well.
Feb 13 '07 #4
On Feb 13, 11:05 am, "Ben Voigt" <r...@nospam.no spamwrote:
"DaTurk" <mmagd...@hotma il.comwrote in message

news:11******** **************@ m58g2000cwm.goo glegroups.com.. .


On Feb 12, 7:12 pm, "Ben Voigt" <r...@nospam.no spamwrote:
"DaTurk" <mmagd...@hotma il.comwrote in message
>news:11******* *************** @k78g2000cwa.go oglegroups.com. ..
Hi,
I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.
It's the "loader lock", not "linker lock" that will bite you with static
native variables in mixed assemblies. Essentially, when static variables
are initialized, the managed runtime typically isn't started yet, so you
can't create managed objects. Destruction has the same issues, static
variables last until the very end, when the managed runtime has typically
shutdown.
I think you might be able to work around with a pointer to gcroot and
lazy
initialization. And you'll have to explicitly delete the gcroot object
to
get cleanup right.
And don't even think of using a native class instance declared as a
global
to perform your init and cleanup, that's the same problem all over again,
although the linker probably wouldn't recognize it.
I'm not entirely sure what lazy init is, could you elaborate please?

Just that initialization waits until the first time you use it, maybe
involving a check for NULL. Writing an explicit initialization function
called from a managed type initializer (also called static constructor or
.cctor) also works well.- Hide quoted text -

- Show quoted text -
OK, I understand. But what I don't understand is how this allows me
to use a static, gcrooted, managed variable in native code. I'm not
sure what I'm missing.

Feb 13 '07 #5

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

Similar topics

4
10695
by: memememe | last post by:
in java if I was calling a synchronized block and wanted to sync it even for static blocks of code I could do a synchronize(theObject.getClass()), can I do a lock(theObject.GetType()) on C# and will it lock for static blocks of code that use that object type?
3
1315
by: Ant | last post by:
Hi, Can you declare a variable as static in C#? If not, then is there a 'module' level area or eqivelant in C# in which you can do this? Thanks in advance Ant
8
6855
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx code-behind and in business logic (C# classes used by the aspx) lose their value. I cannot reproduce this on our development server, so I cannot understand what the cause of all this is. We are using asp.net 1.1 with IIS6 on win2003.
5
2559
by: Frank Wisniewski | last post by:
I use static variables in my asp.net apps instead of application variables to store global parameters, its worked well for me so far but I was wondering if it is efficient. Does anyone know how static variables are handled in asp.net? -- Frank Wisniewski MCSE 4.0, MCP+I, A+ f p w 2 3 @ h o t m a i l . c o m
3
5712
by: Diebels | last post by:
Hi, I have some problems using static variables which results in a core dump. I have attached code and coredump to the end of my message. I am trying to implement a kind of factory design. I have a base class with several sub classes. In runtime I want to create a instance of a sub class and assign it to a base class pointer. Nothing fancy about that. I also want to be able in runtime to decide witch type of sub class that is to be...
7
8060
by: jab3 | last post by:
Does JavaScript have "static" variables. That is, as in C (or local in Perl)? How can I keep a variable in a JavaScript function that doesn't change from call to call? It may not make sense in JavaScript; I'm not sure when the variables are re-set, but I assume it's at each page full reload. But, what if I want to validate a form, and force a user to re-enter something I find invalid, but only do it the first 1 or 2 times. Then, I...
7
3323
by: jois.de.vivre | last post by:
Hi, I'm having some linker issues when using static variables in a class. class TestClass { public: TestClass() { Count++;
1
6423
by: Ian | last post by:
I've just discovered the msclr::lock class in the C++ Support Library online documentation. This seems like a much cleaner way to implement thread protection than using monitor::enter/try/finally/monitor exit. However, I cannot get around one of the warning messages and am requesting help in understanding what is causing the warning. All of the online sample code for the class msclr::lock generates the same warning message. I have...
9
8663
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang Su Gatlin, casual mention was made about using static variables as an alternative to using global variables. This caused me to think of the following: '-----Begin module code
0
9699
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
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
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
10063
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
6838
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();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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
2
3792
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.