Say I have the following function:
bool foo (int a); // This method declaration can not be changed.
How do I create a pthread for this? And how
A bool is functionally equivalent to an int. false
is (usually) 0, and true
is anything else. Thus
void *foo(void *a){
int *a_int = (int *)a;
//do things
bool *x = new bool;
*x = answer;
pthread_exit(x);
}
Then in your main you would get the returned result by casting it back to a bool.
bool *x;
pthread_join(thread,(void *)x);
//Answer is *x