I want to be able to catch the end of a main function and perform additional operations in another thread before process termination in C++.
I have been trying to get the handle to the main thread and then join with it but seems std::this_thread/boost::this_thread do not allow you to get access to the handle for the current thread.
What I would like to do is basically the following:
void thread_function(thread_handler) {
thread_handler.join();
< Perform extra operations before the program finishes its main function >
}
int main() {
< thread_function thread started in LD_PRELOAD>
.... Program runs .....
return 0;
}
In my scenario these two functions have no shared state as the thread_function thread is invoked in a shared library using LD_PRELOAD but I can pass to it anything from the thread that later invokes main(). It may well be that it is not possible to catch the end of the main function but figured I'd ask in case anyone knows about this.