I have a class member functionA which creates a thread to run another functionB. FunctionB would perform some operation and stop after some time ( it is kind of fire and forget function call and the number of functionA calls and threads needed would depends on the run time result). FunctionA would be called multiple times. I realized that the pthread_create would take in pthread_t for the first parameter, and the pthread_t must be available while creating the thread. So, I could not declare it as local like below. So where could I declare the pthread_t?
void classA::functionA(int param)
{
pthread_t t; //could not declare local because functionA might return and destroy t before thread being created.
pthread_create(&t , NULL, functionB, param);
}
void functionB(int param)
{
}