
Peter Dimov-5 wrote:
cowwoc wrote:
Peter Dimov-5 wrote:
cowwoc wrote:
One of my threads has the following logic:
{ at_thread_exit(myHook); while (!shutdownRequested) { // do stuff } }
myHook() { shutdownRequested = true; }
Following your scenario, doesn't this mean that the shutdown hook will never get executed? What will happen? Will exit() hang forever?
It will never get executed. The hook is executed AFTER the thread exits.
So how do you propose I implement the use-case I mentioned?
This way:
void threadproc() { while( !shutdownRequested ) { ... } }
void signal_thread_to_exit_and_wait() { shutdownRequested = true; // join thread }
int main() { // start thread atexit( signal_thread_to_exit_and_wait ); // ... } // exit( 0 ) happens here
That's exactly what I wanted. Thanks Peter! PS: Is there a more reliable mechanism than atexit() that is guaranteed to support more than 32 hooks? Thanks, Gili -- View this message in context: http://old.nabble.com/at_thread_exit%28%29-never-getting-called-tp26053513p2... Sent from the Boost - Users mailing list archive at Nabble.com.