简体   繁体   English

在Windows上增强线程和进程清理

[英]boost thread and process cleanup on windows

In my program I have a static object that creates a boost::thread. 在我的程序中,我有一个创建boost :: thread的静态对象。 The thread is supposed to run until program termination, but it shouldn't be terminated in random state, so I implemented controled thread termination in this static object's destructor. 该线程应该一直运行到程序终止,但不应以随机状态终止,因此我在此静态对象的析构函数中实现了受控线程终止。 The problem is that when main() terminates my thread is terminated before the destructor is called. 问题在于,当main()终止时,我的线程在调用析构函数之前被终止了。

Now the question: is it possible to prevent the thread to be destroyed? 现在的问题是:是否可以防止线程被破坏? Or at least delay it, so that it happens after the destructor is called? 或者至少延迟它,以便它在调用析构函数之后发生?

将终结点从析构函数移动到函数,然后在main结束之前简单地调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM