Boost logo

Boost :

From: Andrey Melnikov (melnikov_at_[hidden])
Date: 2005-08-20 09:28:24


Alexander Terekhov wrote:
> Andrey Melnikov wrote:
> [...]
>
>>>How do you cancel threads?
>
>
> You use pthread_cancel() and rely on mandatory cancel delivery to
> "shall occur" cancellation points. Victim threads shall also be
> prepared to "may occur" delivery for optional cancellation points
> and async-cancel regions (when cancellation is enabled, of course).
>
>
>>The explanation in the FAQ doesn't explain the problem in details.
>>Here's a brief example:
>>
>>bool f1(X x)
>>{
>> X * y = new X;
>> // if f1() is aborted at this point
>> // *y won't be deallocated
>> delete y;
>> return false;
>>}
>
>
> Your f1() is clearly async-cancel-UNSAFE as written. So what?

The example just illustrates that simple asynchronous cancellation
doesn't work in all cases. Threads should be aware of external
cancellation and should be written properly to make the cancellation
(synchronous or asynchronous) safe.

Also remember we didn't spoke about pthread approach. pthread isn't the
only thread abstraction library in the world.

Andrey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk