[c++-pthreads] C++ and posix threads

Ted Baker baker at cs.fsu.edu
Thu Dec 25 14:59:12 UTC 2003


Please forgive my last posting, which was done in haste.  I just
read it, and realized it is nonsense, so I'll answer my own
question.  In the event of thread cancellation the POSIX read()
function does *not* return, but instead enters a control path that
causes it to execute the stack of cancellation cleanup handlers,
and then exit the thread.  The only way you could have
incompatibility would be if the cleanup handlers were not
executed, or the thread did not exit. As others have pointed
out here, there are few existing C applications or libraries 
that make correct use of thread cancellation and cleanup handlers,
and fewer (none?) C++ ones that rely on this.  

On Tue, Dec 23, 2003 at 11:03:14AM -0500, Ted Baker wrote:
> Am I missing something here?
> 
> How do you propose to modify read() to throw an exception and
> still have backwards compatability with applications that expect
> read() to always return (more specifically, to return -1 if it
> fails)?
> 
> It seems to me that the only way you could do this is to
> define a function with a new name, e.g., read_with_exception()
> in your binding.  Otherwise, the linker will not be able to
> tell the difference between your exception-throwing read()
> and the normal C one.  (OK, you might try playing macro games
> with renaming read() subject to a conditional compilation flag
> for C++ programs, but: (1) that is very error prone; (2)
> it would break existing C++ programs that are using calls
> to C-library functions like read().
> 
> --Ted



More information about the c++-pthreads mailing list