|
Boost Users : |
From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2005-08-31 13:11:51
Chris Coleman schrieb:
> I know at present that the Boost Threads implementation does not
> provide a terminate() / cancel() function, but the documentation
> suggests that work is in progress to implement this feature once a
> safe and portable way is found. I was just wondering whether this
> will appear soon in future releases, or if it is likely to be some time?
> At present I can kill a thread internally by simply throwing an
> exception and not catching it. But externally I cannot.
>
From inside it never is a problem to end a thread. Your solution is
just one of
a possible range.
> I have a thread pool server I built some time ago using the pthread
> API and I'm porting it to use Boost Threads. The server has add() and
> remove() thread methods. Within the remove function under the pthread
> implementation I could call pthread_cancel(thrID) and that would be
> that, Obviously I cant call thread.cancel() as I'd like here and was
> wondering if there were any simple ways to signify that a particular
> thread should terminate?
The standard answers go along the lines:
Have the thread signalled by some means (condition, pipe,... ) and check
a flag
that will tell it to end.
However that is not what true cancellation is about. And if you
carefully think
about it you will find that cancellation often is abused to end the thread
where a coordinated shutdown would be in order. I.e. most often you do
not need true cancellation.
I was in a similar situation, but still did not want to code this generic
"end the thread" (I am avoiding cancel here) into every thread.
It might be a year or so now, that I suggested a thread alert framework
that is entirely built on top of the currenty boost thread. And I am
sucessfully using it. It provides me almost everything I would
have expected from cancellation. (Altough I know it cannot provide
true async cancellation.)
As far as I remember I also added an example demonstrating
fake cancellation behaviour.
But surprisingly, given the ever popping up questions of cancellation
being added to the library I never got any feedback on my proposal.
So I invite you to give it a chance.
The thread alert can be downloaded from the file area (the vault).
Regards,
Roland
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net