From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-13 13:08:37
Boy, I love it when I read someone's post who really understands
----- Original Message -----
From: "Tom Becker" <voidampersand_at_[hidden]>
> Throwing an exception will do the clean up. But many thread
> implementations don't provide a way to interrupt a thread and force
> it to execute code (such as a throw statement) that isn't already
> compiled into the thread at that point.
Good thing, too!
> Also, exception-safe code
> depends on knowing that certain ranges of code, such as simple
> copying a pointer, can never throw. Interrupting a thread can be safe
> only if the cancellation exception is thrown from a point where the
> code expects some exception may be thrown.
> Since the runtime can't
> read the mind of the programmer, this means the programmer must
> supply hints. The simplest approach is for the thread to occasionally
> call a CheckForCancellation() function that checks a variable and
> conditionally throws a cancellation exception. The thread won't get
> canceled right away, but at least it will be canceled at a safe time.
Many people object to that sort of design (I don't), but it seems to me that
it's the only way to deal with lots of these situations. Cooperative
multithreading imposes similar constraints. Well, you can always hijack
operator new() and hope that's called often enough ;^).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk