Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - C++ and pthread_cancel: (3 Items)
   
C++ and pthread_cancel  
Should pthread_cancel on a thread cause the destructor of objects that go out of scope to be called?  That apparently 
doesn't happen on QNX.  It DOES happen on other platforms.  Is there something I need to do (flag setting?) to make this
 work.  Example code is attached.  I expected to get:

"In destructor" after the cancel, but that doesn't happen. 
Attachment: Text test_cancel.cc 1.12 KB
Re: C++ and pthread_cancel  
Hi John,

The QNX pthreads implementation is essentially a C library - it doesn't know anything about C++.   Some other clibs 
(such as the GNU clib) include specialized code that interacts with the C++ library in the case of thread cancellation 
to make it behave as if thread cancellation is a magic, uncatchable exception; this leverages the usual C++ stack 
unwinding code to destruct stack local variables.

It is technically possible to port the GNU clib approach to QNX.   I have an x86 implementation of something similar, 
although I wrote it before finding out that the GNU clib behaves this way (it didn't back when I started on that 
project).  Consequently my implementation is somewhat crude by comparison, and not easily portable to other 
architectures.  I did take a look at the GNU implementation, though, and my read of it suggests it should be possible to
 port the key bits to operate with the QNX clib, although it would probably involve a dive into the g++ ABI and 
exception handling layer.  The relevant code is in the nptl sub-library, specifically with regards to stack unwinding.

Hope this helps some,

-Will
Re: C++ and pthread_cancel  
Will,

Thanks for the reply.  I appreciate the explanation.

I can do what I want to do without thread cancellation.  It just makes for a little more work, although there are some 
who don't like thread cancellation under any circumstances.

John