.net - .NET中的GC期间安全地暂停线程

标签 .net garbage-collection

.NET中的线程在GC期间暂停。 CLR如何安全地暂停线程?通过像Win32 SuspendThread API这样的残酷方式停止线程可能会有什么风险?

最佳答案

这是关于.NET Compact Framework的,但是我认为对于正常的.NET是正确的:http://blogs.msdn.com/b/abhinaba/archive/2009/09/02/netcf-gc-and-thread-blocking.aspx

Before actually running GC the CLR tries to go into a “safe point”. Each thread has a suspend event associated with it and this event is checked by each thread regularly. Before starting GC the CLR enumerates all managed threads and in each of them sets this event. In the next point when the thread checks and finds this event set, it blocks waiting for the event to get reset (which happens when GC is complete).

关于.net - .NET中的GC期间安全地暂停线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4418356/

相关文章:

.net - "Splicing"代码写入 Windows 可执行文件

javascript - 阻止网络浏览器中的自定义广告对话框

java - 为什么当数据集较小时,SerialGC 比 ParallelGC 更快?

java - 当我们显式调用垃圾收集器方法时会发生什么?

c# - List<Class> 到 List<string>

.net - 使用浮点值进行单元测试

c# - 在 IDisposable.Dispose 中拦截异常

java - 合成 lambda 类的神奇类卸载?

java - 为什么垃圾收集启动时 "from"幸存者空间不为空?

garbage-collection - 没有垃圾收集的引用计数