Boost logo

Boost Users :

Subject: Re: [Boost-users] boost thread query
From: Sean Farrow (sean.farrow_at_[hidden])
Date: 2010-11-24 07:06:49


Hi:
If I do a thread.join, will the main thread continue, i.e I have a while loop in the main thread waiting for a windows message, if I put thread.join in there I don't want the loop to stop.
Cheers
Sean.

-----Original Message-----
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Igor R
Sent: 24 November 2010 12:00
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] boost thread query

> 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 mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


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