0

Hi,
I am trying to accessing a function from thread created from a class member function.
but i am getting error does not come under scope .

please help to slove the problem.

below is the scenatrio..

typedef void (*Fptr)(type *ptr);

class test{
    public :
    Fptr fun;
    void init(Fptr fun1);
    void start(
};

void test :: init(Fptr fun1)
{

 fun = fun1;
 start(); 
}

void test :: start(){
pthread_create(...,threadfunc);
}


void static threadfunc(void *)
{
    fun(¶m); // getting error here
}
2
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by clife
0

This is because the function "threadfunc()" is not a member of the class test. You need to pass threadfunc() an argument to fun. Example:

void test :: start()
{
    pthread_create(...,threadfunc, (void*)fun);
}
void static threadfunc(void *pFun)
{
    Fptr fun = (Fptr)pFun;
    fun(¶m); // getting error here
}

I don't know if this will run since I don't have the time right now to test it out, but it should be pointing you in the right direction. Note that the last argument of pthread_create() is NOT the thread function, but the ARGUMENT that is passed to it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.