Boost logo

Boost Users :

Subject: [Boost-users] Problem with boost:thread
From: Daniel Veneros (dann.vd_at_[hidden])
Date: 2010-03-04 11:47:13


Hey, I'm trying to start a thread from a Class but the only way I did it was
using a pointer.
The thing is that when I assign the thread to the pointer it wont start
unless I use join().
I need it to star right away is created just like when I create a thread
(boost::thread myThread(funcName);)
I was trying to use thread_group to do this, but create_thread is not
working.
*Here's an example of what I was doing:*
*(Here I used the pointer)*
class Thread {

public:
    Thread(){};
    virtual ~Thread(){};
    virtual void run() = 0;
    void start(){m_Thread = new boost::thread( &Thread::run, this ); };
//wont start unless I add m_Thread.join();

private:
    boost::thread* m_Thread;

};

*and now... I am trying to use thread_group:*

class Thread {

public:
    Thread(){};
    virtual ~Thread(){};
    virtual void run() = 0;
    void start(){g_Thread.create_thread(&Thread::run); };

private:
    boost::thread_group g_Thread;

};

*But I receive an error:*
/usr/local/include/boost/thread/detail/thread.hpp: In member function 'void
boost::detail::thread_data<F>::run() [with F = void (Thread::*)()]':
main.cpp:61: instantiated from here
/usr/local/include/boost/thread/detail/thread.hpp:56: error: must use '.*'
or '->*' to call pointer-to-member function in
'((boost::detail::thread_data<void
(Thread::*)()>*)this)->boost::detail::thread_data<void (Thread::*)()>::f
(...)'
make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1
Im using netBeans on Mac OS X 10.6.2
Anyone knows how should I create this? or how to use simple boost::thread
and launch it without using join()??
Thanks!!!

Dann



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