[c++-pthreads] Re: pthread_cancel and EH: let's try this again

Peter Dimov pdimov at mmltd.net
Sun Jul 17 23:15:35 UTC 2005


Nathan Myers wrote:

> 2. Existing thread-safe and exception-safe C and C++ libraries that do
> *not* take cancellation into account should still work.

Even when cancelled?

> (This implies
> that C library calls, including system calls, never throw, by default
> or during normal operation; likewise for C++ destructors, and C++
> functions with any throw specification.)

[...]

> 7. We may assume we can hijack/shadow standard system and library
> calls and add our own semantics, such as causing them to report
> failure (perhaps with distinguished ERRNO codes) under circumstances
> where they would otherwise have succeeded, or (under C cancellation)
> entered some sort of cleanup mode.  (Scott Lamb has experience in this
> area.)

I don't see how this is going to work.

Consider a pure C program that calls a cancellation point, 'fwrite' for 
instance. fwrite "throws" - unwinds the stack and calls Posix cleanup 
handlers.

Now consider a pure C++ program that calls that same 'fwrite'. It doesn't 
throw, it signals failure.

But what does fwrite do in a mixed C/C++ program? "Throw" when called from C 
code and return failure when called from the C++ part? What if a C function 
calls fwrite and is itself called by C++ code? No matter what fwrite does, 
it will break the C part or the C++ part, or maybe both.




More information about the c++-pthreads mailing list