boost::thread no parameter?

Greetings, I'm wondering why there is no option to pass a parameter to a thread function with boost's threads. With pthreads and Windows CreateThread I'm used to casting an object to a void*, and retrieving the object within the thread function. The only thing similar with boost::thread seems to be to create a struct with an operator()() and a constructor that takes a void*. operator()() then calls an external function with the passed void*. Just curious about this design decision. --M Peltzer

On Mar 10, 2004, at 6:27 PM, GoochRules! wrote:
I'm wondering why there is no option to pass a parameter to a thread function with boost's threads. With pthreads and Windows CreateThread I'm used to casting an object to a void*, and retrieving the object within the thread function. The only thing similar with boost::thread seems to be to create a struct with an operator()() and a constructor that takes a void*. operator()() then calls an external function with the passed void*.
Just curious about this design decision.
I would guess because it is so easy (at least with the right tools!) to create function objects that adapt a function from one that takes parameters to one that doesn't. void foo(int, double); void bar(A*); struct A{}; int main() { thread t1(bind(foo, 1, 2.5)); thread t2(bind(bar, new A)); } -Howard

At 07:49 PM 3/10/2004, Howard Hinnant wrote:
On Mar 10, 2004, at 6:27 PM, GoochRules! wrote:
I'm wondering why there is no option to pass a parameter to a thread function with boost's threads. With pthreads and Windows CreateThread I'm used to casting an object to a void*, and retrieving the object within the thread function. The only thing similar with boost::thread seems to be to create a struct with an operator()() and a constructor that takes a void*. operator()() then calls an external function with the passed void*.
Just curious about this design decision.
I would guess because it is so easy (at least with the right tools!) to create function objects that adapt a function from one that takes parameters to one that doesn't.
void foo(int, double); void bar(A*);
struct A{};
int main() { thread t1(bind(foo, 1, 2.5)); thread t2(bind(bar, new A)); }
Seems like thread/doc/thread.html should give an example similar to the above. Maybe modified with a join() and changed so it doesn't leak:-) --Beman

At 07:49 PM 3/10/2004, Howard Hinnant wrote:
On Mar 10, 2004, at 6:27 PM, GoochRules! wrote:
I'm wondering why there is no option to pass a parameter to a
function with boost's threads. With pthreads and Windows CreateThread I'm used to casting an object to a void*, and retrieving the object within the thread function. The only thing similar with boost::thread seems to be to create a struct with an operator()() and a constructor that takes a void*. operator()() then calls an external function with the passed void*.
Just curious about this design decision.
I would guess because it is so easy (at least with the right tools!) to create function objects that adapt a function from one that takes parameters to one that doesn't.
void foo(int, double); void bar(A*);
struct A{};
int main() { thread t1(bind(foo, 1, 2.5)); thread t2(bind(bar, new A)); }
Seems like thread/doc/thread.html should give an example similar to
"Beman Dawes"
above. Maybe modified with a join() and changed so it doesn't leak:-)
I'll try to work on this soon.
--Beman
participants (4)
-
Beman Dawes
-
GoochRules!
-
Howard Hinnant
-
Michael Glassford