开发者

Native thread behavior at the time of garbage collection

When the runtime starts garbage collection, it suspends all managed threads.. My application 开发者_开发问答has both managed and unmanaged componenets. There is a possibility that a native thread from the unmanaged code can enter into the managed code when runtime executes the garbage collection activity.

How does .net handles this? Will .net suspends the native thread or something else happens?


As I understand it, the reason the managed threads are suspended, is that the managed heap may be compacted during collection. If this happens references to managed objects must be adjusted. I take it that your native threads are not using objects on the managed heap and thus should not be affected by garbage collection.

If your native threads do access managed objects, you should pin these. This will prevent the GC from moving the objects during compaction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜