RE: [boost] boost.thread : Can one create a thread with an objectmember function?

Thanks! Since I don't need the class anymore I don't need to use bind, but I'll keep this in mind for the future. Thanks again, Tim -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Cory Nelson Sent: Monday, November 22, 2004 5:58 PM To: boost@lists.boost.org Subject: Re: [boost] boost.thread : Can one create a thread with an objectmember function? Yup! boost::thread(boost::bind(&classname::method, boost::ref(thisptr))); On Mon, 22 Nov 2004 10:50:17 -0500, Tim Laplaca <tlaplaca@voiceglo.com> wrote:
I am very new to boost, I apologize if this has been asked before. I searched the mailing list archive but could not find an answer to my question.
I was successful creating threads with functions that are not members of objects, but when I try to create threads with a pointer to an object member I get compilation errors (MS Visual Studio .NET).
Examples:
class objclass;
typedef void (objclass::*pmf)(); // ptr to member func
class objclass
{
public:
objclass() : thread_id (0) { p=&objclass::dowork; }
inline setthreadid(int x) {thread_id = x;}
inline setvaltwo(std::string str) {valtwo = str;}
void dowork();
pmf p; // pointer to dowork member function
int getthreadid() {return thread_id;}
std::string getvaltwo() {return valtwo;}
private:
int thread_id;
std::string valtwo;
};
void objclass::dowork()
{
}
(In the main...)
boost::thread_group thrds;
objclass * objthread;
objthread = new objclass;
thrds.create_thread( (objthread->p) );
I get the following error:
c:\Boost\include\boost-1_31\boost\function\function_template.hpp(427): error C2664: 'void
boost::function0<R>::assign_to<Functor>(FunctionPtr,boost::detail::funct
ion::function_ptr_tag)' : cannot convert parameter 2 from 'boost::detail::function::member_ptr_tag' to 'boost::detail::function::function_ptr_tag'
with
[
R=void,
Functor=pmf,
FunctionPtr=pmf
]
Is there a way around this problem, or is it simply not possible to make threads from object members with boost?
Thanks,
Tim
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Cory Nelson http://www.int64.org _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (1)
-
Tim Laplaca