I want to use TBB threads in C++ and want to use “tbb_thread” API.
for example i have static function in class as below
template < typename threadFuncParamT >
class ThreadWrapper
{
public:
static int ThreadRoutineFunction(void* pParam);
};
I want to use tbb_thread API to spawn a thread with “ThreadRoutineFunction” which is defined above class. How can i achieve this using tbb_thread API. please note that i have to pass pointer to the thread routine function. Can any one give me simple example how to do this?
It sounds like your question is really “how do I get a pointer to a
staticmember function?”C++ doesn’t officially have a way to do that. However, according to the C++ FAQ (the Note in question 2), “pointers-to-
static-member-functions are usually type-compatible with regular pointers-to-functions.”Your options are:
Use a regular pointer to function, point it at your
staticmember function, see if your compiler complains:Do what the FAQ suggests, and declare your function
extern "C"as well asstatic(you’ll also have to declare the pointer to the function asextern "C", and you won’t be able to overload the function):Create an additional function that does nothing but call the
staticmember function: