[c++-pthreads] Re: pthread_cancel and EH: let's try this again
Peter Dimov
pdimov at mmltd.net
Sat Jul 16 15:58:08 UTC 2005
Alexander Terekhov wrote:
> Peter Dimov wrote:
> [...]
>> I don't get it. What is this code supposed to achieve?
>
> It's a dtor. The logic is this:
>
> Detect whether unwinding caused by cancel delivery is taking place
>
> yes:
>
> reassert cancellation;
> invoke fclose() -- it will throw (and most likely not flush),
> but will close/free resources nevertheless;
> catch and finalize cancel exception;
>
> no:
>
> invoke fclose() fully prepared to hit cancel, and if canceled
> (see above) simply reassert cancellation;
And what is gained compared to
~X() throw()
{
fclose( file );
}
?
Not that fclose should be a cancellation point, of course.
Do you mean something along the lines of
~X() throw()
{
try
{
lengthy_or_blocking_operation();
}
catch( ... )
{
}
}
where one would want to have cancellation enabled in
lengthy_or_blocking_operation, even when ~X is called by stack unwinding?
I'm not sure how compelling is this example.
More information about the c++-pthreads
mailing list