CLR behavior about accessing data during garbage collection working

H

Hyun-jik Bae

I got a curiosity while using CLR.
How can it be done that accessing object data by CLR application is safe
even while garbage collector is working? Is the GC thread running in
realtime priority for this for example?
Please reply. Thanks in advance.

Hyun-jik Bae
 
G

Guest

The CLR pauses all threads while garbage collecting. Thats why it is a
performance hit to call it yourself and to keep invoking it with short term
memory allocations.

Ciaran O'Donnell
 
M

Michael Nemtsev

Hello Hyun-jik Bae,

Just to add Ciaran's post:
GC pause nothing, it just ask CLR to suspend/resume threads.
It's not just simple suspension, there are some cases how threads are suspended
based on whether threads are in managed code or not

H> I got a curiosity while using CLR.
H> How can it be done that accessing object data by CLR application is
H> safe
H> even while garbage collector is working? Is the GC thread running in
H> realtime priority for this for example?
H> Please reply. Thanks in advance.
H> Hyun-jik Bae
H>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
G

Gabriel Lozano-Morán

I always thought that the GC will not collect managed resources when they
are in use and that's exactly what he is saying no? Unmanaged resources
that's a different story that's why we have GC.KeepAlive()

Gabriel Lozano-Morán
 
B

Ben Voigt

Hyun-jik Bae said:
I got a curiosity while using CLR.
How can it be done that accessing object data by CLR application is safe
even while garbage collector is working? Is the GC thread running in

It isn't.... the gc moves everything. That's why the GC suspends all
threads in managed code before it starts running.
 
M

Michael Nemtsev

Hello Ben,

A small addition - GC calls functions to do the suspension and the resumption
as a service provided in the CLR.
It's the work of CLR and EE(Execution Engine) to manage this

BV> BV>BV> It isn't.... the gc moves everything. That's why the GC suspends
BV> all threads in managed code before it starts running.
BV>---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top