Subj : Re: pthreads with C++ To : comp.lang.c++,comp.programming.threads From : Torsten Robitzki Date : Tue Apr 19 2005 09:19 pm John wrote: > The problem seems to be that I need > > dinsert::eval(M); call. The type of M depends on D. > And I cant do this at runtime. If I write a function that takes > both D and M as input, my code gets messed up since > then the compiler does not know the type of M at compile time. > > Thanks for ur help, > --j > Then pass a structur with a M and pointer to a function taking a M to the thread function (note that the thread function have to have C binding). template struct dinsert { static void eval(M); static void eval(void* m) { eval(*static_cast(m)); } }; struct dipatch { void(func*)(void*); void* param; dispatch(void(f*)(void*), void* p) : func(f), param(p) {} }; extern "C" void* thread_func(void* p) { std::auto_ptr disp(static_cast(p)); disp->func(disp->param); } int main() { // call dinsert<5,int>::eval(17); pthread_create(thread_func, new dispatch(&dinsert<5,int>::eval(int), 17), 0); } I did not compiled it, but I hope you can get the idea. And as usual boost have this already. for deferred call function calls: http://www.boost.org/doc/html/function.html for threads: http://www.boost.org/doc/html/threads.html regards Torsten .