.NET垃圾收集器 - 它的线程优先级是什么? [英] .NET Garbage Collector - what is its thread priority?

查看:90
本文介绍了.NET垃圾收集器 - 它的线程优先级是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些很棒的文章( Maoni Richter#1 Richter#2 )给出了关于GC的理论和实践的许多细节,但是我找不到任何说明GC的线程优先级如何设置。



我发现的最接近这个的是Finalizer线程与应用程序异步运行并且处于高优先级。



我一直认为这是一个低优先级线程,但越来越多地阅读它似乎是错误的(因为GC必须阻止所有其他线程,并且您不希望让应用程序依赖于一个低优先级的线程为了r



有谁知道确切知道实际优先级应该是什么?

,Richter解释说:


CLR中通过C#一个特殊的高优先级CLR线程致力于调用 Finalize 方法

请参阅第20章的Finalization Internals标题)

这是他谈论垃圾收集器线程的唯一上下文。在本章稍早的部分,他解释说垃圾收集是为了响应以下事件之一而开始的:


  • 第0代已满

  • 调用 GC.Collect

  • Windows报告内存不足情况

  • CLR卸载AppDomain

  • CLR正在关闭



...这表明垃圾收集器创建的唯一线程是这个单一的高优先级终结器线程。



编辑:然后他继续在Concurrent Collection中解释:
$ b


在运行工作站版执行引擎的多处理器系统上,垃圾收集器有一个额外的后台线程来在应用程序运行时同时收集对象。 [...] 垃圾收集器有一个普通的优先级后台线程,用于标记不可访问的对象。


I have found some great articles (Maoni, Richter #1, Richter #2) giving many details as to the theory and practice of the GC, yet I cannot find anything that states how the GC's thread priority is set.

The closest I've found is this one that states that the Finalizer thread "runs asynchronously to the application and at a high priority."

I always thought that it was a "low-priority" thread, but reading more and more about it that seems to be wrong (since the GC has to block all your other threads, and you don't want to have your app depend on a low-priority thread in order to resume in a timely fashion).

Does anybody know for sure know what the actual priority is supposed to be?

解决方案

In CLR via C#, Richter explains that:

A special high-priority CLR thread is dedicated to calling Finalize methods

(see the "Finalization Internals" heading of chapter 20)

This is the only context in which he talks about a garbage collector thread. A little earlier in the chapter, he explains that garbage collection is started in response to one of the following events:

  • Generation 0 is full
  • Call to GC.Collect
  • Windows is reporting low memory conditions
  • The CLR is unloading an AppDomain
  • The CLR is shutting down

...which suggests that the only thread created by the garbage collector is this single, "high-priority" finalizer thread.

Edit: He then goes on, in "Concurrent Collection", to explain that:

On a multiprocessor system running the workstation version of the execution engine, the garbage collector has an additional background thread to collect objects concurrently while the application runs. [...] The garbage collector has a normal priority background thread that marks unreachable objects.

这篇关于.NET垃圾收集器 - 它的线程优先级是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆