boost thread and process cleanup on windows

2019-05-30 10:36发布

问题:

In my program I have a static object that creates a 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.

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?

回答1:

Move the termination from the destructor to a function and simply call it before main ends.