|
Boost Users : |
Subject: Re: [Boost-users] boost thread query
From: Igor R (boost.lists_at_[hidden])
Date: 2010-11-24 07:00:19
> I have two threads that are started by a class created by the applications
> main thread.
>
> Can the thread function be a private member of that class or does it need to
> be public?
The thread doesn't care whether they are private or public, but if you
want to create the thread from outside the class, then the thread
function should be visible and accessible at the point where you
reference it.
> When the application exits I need the threads to be notified and exit.
> What is the best way of handling this? I need this to be cross platform but
> in windows I would have used a waitforSingleObject and signalled the event
> when the main thread wants to exit.
Use thread::join() member function to wait on threads to complete.
You can notify threads with condition_variable, or use some
applicative methods, depending on what these threads actually do.
> Could I use a condition for this, and do a do while loop waiting on the
> condition to be notified, if I do this do I need a mutex just for the
> condition?
Take a look at the following example to see how to handle condition_variable:
http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
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