gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:40:55 25 4
gpt4 key购买 nike

.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com