Boost logo

Boost Users :

From: Kevin Heifner (heifner_k_at_[hidden])
Date: 2006-03-03 20:35:45


Olaf van der Spek wrote:
> I'm converting code using pthreads to boost::thread.
> I've now got this code:
> Cdns_worker::Cdns_worker():
> m_run(true),
> m_thread(boost::bind(&Cdns_worker::run, this))
> {
> // pthread_cond_init(&m_condition, NULL);
> // pthread_mutex_init(&m_mutex, NULL);
> // pthread_create(&m_thread, NULL, Cdns_worker::run, this);
> }
>
> The data the thread is using is in Cdns_worker, but it seems
> impossible to delay the thread creation until the end of the
> constructor, like I could with pthreads.

Not sure why you need to delay thread creation until the end of
the constructor. Why not just make sure that m_thread is the
last attribute in your header so that it is created last?

> What should I do in this case?

You could do this:

m_thread_group.create_thread(boost::bind(&Cdns_worker::run, this));

Or this:

boost::scoped_ptr<boost::thread> m_thread;
m_thread.reset(new boost::thread(boost::bind(&Cdns_worker::run,
this));

> I also noticed boost::thread has a default constructor but it's not
> copyable. What is the purpose of this default constructor?

Creates a boost::thread object associated with the current thread
of execution.

> And are there any boost::thread examples?
> I couldn't find them in the documentation.

C:\boost_1_33_1\libs\thread\example\*.cpp

KevinH

-- 
Kevin Heifner  heifner @ ociweb.com  http://heifner.blogspot.com
           Object Computing, Inc. (OCI) www.ociweb.com

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