From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2007-02-08 10:03:34
Eugene Lyubimkin <yf_at_[hidden]> writes:
> I want to propose a new feature in *Boost.Threads
> *Now class _boost::thread_ have only one constructor:
> /thread::thread( const function0<void>& )
> /So we cannot send any parameter to thread's main function, because its
> prototype have no parameters.
> My proposal: let add constructor
> /thread::thread( const function1<void, void*>& )/
> Parameter with type /void* /will be sent to thread function.
> Currently *Boost.Threads *supports Win32 API and POSIX API.
> Both these APIs support sending one parameter /void*/ to thread's main
You're right that the underlying APIs support sending a single parameter to
the thread function, and you're also right that the thread constructor only
takes a function<void>. However, this is not as limiting as it appears. The
parameter is a function object, not a function pointer, so you can create your
functor any way you like. For example, you can use boost::bind to pass
parameters to a normal function:
void some_func(int i);
boost::thread some_thread(boost::bind(some_func,42)); // thread runs some_func(42)
-- Anthony Williams Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk