Are destructors for automatic objects guaranteed to execute if a thread is cancelled asynchronously?
Are destructors for automatic objects guaranteed to execute if a thread is cancelled asynchronously?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In theory, it SHOULD work fine, but it’s worth testing with your platform.
Cancelling a thread eventually ends up invoking
pthread_exit(), which as far as I can tell from googling will invoke destructors. It does this by throwing some kind of ‘guaranteed uncaught’ exception all the way out to the thread wrapper, so all your stack-based objects get destructed in the correct order.See this page, for example. And this blog post: