Boost logo

Boost :

From: Tim Laplaca (tlaplaca_at_[hidden])
Date: 2004-11-23 15:21:34


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_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Cory Nelson
Sent: Monday, November 22, 2004 5:58 PM
To: boost_at_[hidden]
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_at_[hidden]>
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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk