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

问题描述

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



我发现的最接近这个的是Finalizer线程



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



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

,Richter解释说:

请参阅第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:

(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:

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

10-25 01:27