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