简体   繁体   English

全局变量未在主线程中销毁?

[英]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.

相关问题 C ++静态变量总是在主线程上被破坏吗? - are C++ static variables always destructed on main thread? 在所有线程局部存储对象被破坏后,是否保证全局对象被破坏? - Are global objects guaranteed to be destructed after all thread-local-storage objects are destructed? 如何在不使用全局变量的情况下向外部线程通知主线程状态? - How to notify outside thread of main thread state without using global variables? 并非所有本机全局变量都在混合模式.Net应用程序中被破坏,因为超时时间为2秒 - Not all native global variables are destructed in mixed-mode .Net application because of a 2-second time-out omp线程池什么时候被破坏 - When will omp thread pool get destructed 在main之前调试对全局变量的赋值 - debugging assignments to global variables before main 全局变量的静态初始化是否在`main()`之前完成? - Is the static initialization of global variables completed before `main()`? 访问线程内的主要对话框变量(MFC) - Access to main dialog variables within thread (MFC) 我的函数没有更新全局变量/main 中使用的变量 - My functions are not updating global variables / the variables used in main 全局变量和主要变量之间有什么区别? - What's the difference between global variables and variables in main?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM