Using Threads: Compile Error

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Threads: Compile Error

Agarwal, Abhishek
Hello All,
 
I am new to boost and hence i would like to ask a few questions on multi
threading feature of this library. I am ataching a program can some one help
to find out why i am getting this error as given follows
 
Master.cpp: In member function `void master::Master::createt()':
Master.cpp:17: error: no matching function for call to
`boost::thread::thread(<unknown type>)'
/opt/boost/include/boost-1_33_1/boost/thread/thread.hpp:35: note: candidates
are: boost::thread::thread(const boost::thread&)
/opt/boost/include/boost-1_33_1/boost/thread/thread.hpp:38: note:
boost::thread::thread(const boost::function0<void,
std::allocator<boost::function_base> >&)
/opt/boost/include/boost-1_33_1/boost/thread/thread.hpp:37: note:
boost::thread::thread()

Thanks
Abhishek

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

master.h (612 bytes) Download Attachment
Master.cpp (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using Threads: Compile Error

Anthony Williams-3
"Agarwal, Abhishek" <[hidden email]> writes:

> I am new to boost and hence i would like to ask a few questions on multi
> threading feature of this library. I am ataching a program can some one help
> to find out why i am getting this error as given follows
>  
> Master.cpp: In member function `void master::Master::createt()':
> Master.cpp:17: error: no matching function for call to
> `boost::thread::thread(<unknown type>)'
> /opt/boost/include/boost-1_33_1/boost/thread/thread.hpp:35: note: candidates
> are: boost::thread::thread(const boost::thread&)
> /opt/boost/include/boost-1_33_1/boost/thread/thread.hpp:38: note:
> boost::thread::thread(const boost::function0<void,
> std::allocator<boost::function_base> >&)
> /opt/boost/include/boost-1_33_1/boost/thread/thread.hpp:37: note:
> boost::thread::thread()

The constructor for boost::thread takes a function with no parameters, through
the boost::function0 template. Non-static member functions do not fit the bill
--- they need an object to be invoked against, the implicit 'this' parameter.

You can bind the member function with an appropriate 'this' parameter to make
it callable without parameters using boost.bind:

#include "boost/bind.hpp"

void master::Master::createt(){
    thread t1(boost::bind(&Master::sleepslave,this));  
}

HTH,

Anthony
--
Anthony Williams
Software Developer
Just Software Solutions Ltd
http://www.justsoftwaresolutions.co.uk

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost