|
Boost Users : |
From: hlh771
Date: 2003-01-11 12:09:32
--- In Boost-Users_at_[hidden], William E. Kempf <wekempf_at_c...>
wrote:
> > From: "hlh771 <hlh771_at_y...>" <hlh771_at_y...>
> >
> > How to stop(or cancel) a thread? Suppose I have a main thread and
a
> > worker thread, the worker thread does something looply,and when
the
> > main thread get a message indicating the process should exit, I
want
> > stop the worker thread,how to do that?I have read other thread
> > library,their thread class supply a method called stop or cancel
> > which stops the thread. Their Implementation is:the thread class
has
> > a data member indicating whether the thread should stop,and the
> > thread function looply check the data member whether the thread
> > should stop.Generally the data member's type is a bool or Event.
> > Is it the best way to stop the thread? How the boost to deal with
> > this?
> > Thanks in advance.
>
> Today you should use a flag and a condition/mutex combination.
Direct support for cancellation is being provided in a future release.
>
> William E. Kempf
> wekempf_at_c...
Thanks a lot.
Can I only use a bool flag?Although more than one thread may access
the flag and at least a thread write the flag, but it do not seems to
cause problem, and I have used this means in a one multithreading
program(not use boost/threads),it runs good.
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