public
Created

C++ invoker

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Heres a rough idea, how you can use this with any function object:
template<class F>
struct invoker
{
static void start(void * x)
{
(*(reinterpret_cast<F*>(x)))();
delete x;
}
};
 
template<class F>
int create(pthread_t *thread, const pthread_attr_t *attr, F f)
{
return pthread_create(thread, attr, &invoker<F>::start, (void *) new F(f));
}
It allocates the function object on to the heap which may not be the best option.
 
http://www.reddit.com/r/cpp/comments/xgnqi/c_reflection_in_under_100_lines_of_code/c5mnaga

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.