Skip to content

@ckaminski /gist:3318511
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
C++ invoker
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.