I have a following scenario,
void* Refresh(void *)
{
usleep(10);
..
}
static void RefreshViews()
{ ...
pthread_t t;
pthread_create( &t, NULL, &Refresh, NULL);
...
}
I want to run a thread at the end of RefreshViews() function. For it to work(temp solution) properly, I have added sleep in another thread at the beginning of its execution in Refresh() function.
How can I handle this situation better?
There are three methods you can use:
Like I said in my comment, start the thread just before you leave the function.
Create the thread in the function calling
RefreshViews.Have an extra function, that acts as a proxy to the real function, and which creates the thread:
One thing about the first method, is that you have to remember to create the thread if you have an explicit
returnbefore the end of the function. Or usegototo go to the thread creation instead ofreturn.