[英]Global variables not destructed in main thread?
I have a mixed-mode executable and I noticed that the constructor of my native global variables is called in the main thread, but the destructor is called in some other thread. 我有一个混合模式的可执行文件,并且我注意到本机全局变量的构造函数在主线程中被调用,而析构函数在其他某个线程中被调用。
The name of thread is 'Thread::intermediateThreadProc'. 线程的名称为“ Thread :: intermediateThreadProc”。
What is the reason for this? 这是什么原因呢? And what is this 'Thread::intermediateThreadProc' thread? 这个“ Thread :: intermediateThreadProc”线程是什么?
Thanks. 谢谢。
Thread::intermediateThreadProc() is a little helper function in the CLR that's used as the thread start function for any thread started by the CLR. Thread :: intermediateThreadProc()是CLR中的一个小辅助函数,用作CLR启动的任何线程的线程启动函数。 Find it back in the SSCLI20 source, src\\vm\\threads.cpp 在SSCLI20源src \\ vm \\ threads.cpp中找到它
Seeing this run on another thread is to be expected. 可以看到在另一个线程上运行。 Cleanup code runs when the appdomain gets unloaded. 当卸载appdomain时,将运行清理代码。 The CLR logic for it is mighty complicated, but it looks like it will run when the appdomain runs the finalizer thread for the last time to clean up the heap. 它的CLR逻辑非常复杂,但是看起来好像它将在appdomain最后一次运行终结器线程以清理堆时运行。 You can assume that all managed objects are dead and there are no other threads running. 您可以假定所有托管对象均已失效,并且没有其他线程在运行。 Beware that your code is subject to the two second finalizer thread timeout. 请注意,您的代码受两秒钟终结器线程超时的限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.