[Boost.Threads] New Feature: thread function parameter

Hello! 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 function. Sorry for my English. ----------------------------------------------------------- Best, Eugene Lyubimkin, the Ukrainian C++ developer.

Eugene Lyubimkin <yf@a.ua> 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 function.
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 -- 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

Eugene Lyubimkin wrote:
*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.
struct Foo { void operator() { /* some code */ } /* some members */ }; Foo foo; boost::thread(foo); the members of the functor advantageously replace void*.
participants (3)
-
Anthony Williams
-
Eugene Lyubimkin
-
Mathias Gaunard