pthread_cancel() question

I have a question regarding the pthread_cancel() call.

The docs state first any cleanup handlers are executed and then the threads data specific descructor functions.

Does this mean that stack is unwound for my thread and that all C++ class destructors are invoked?

I’m curious because I have some threads that I sometimes want to cancel. But these threads may control mutex’s. I know you can specifically do it in the cleanup handler. But if you don’t know what mutex’s you own (which you might not if your calling library code), you can hardly put them in the cleanup handler.

On the other hand if the stack unwinds during pthread_cancel() I will be OK because I unlock any mutexs when a function exits (hence unwinding the stack guarantees mutexs are unlocked).


That should be easy to test no. Just create an object and put a cout in the destructor. That should answer the question.

(10 minutes later) I couldn’t resists and wrote a small test program. The C++ destructor are NOT called, which is kind of expected.


Thanks for doing the small test that I would have ended up doing myself if you hadn’t answered it for me.

Too bad it doesn’t work.

I need to figure out another way to do this that will allow me to release mutexes that might be held.