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
}

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.

Thanks i am gonna try that, and let u know

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.