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
As far as you're dealing only with bools (which are, in fact, integers) it's possible, however not recommended, to cast the function to a pthread function type, as a pointer is compatible with (some) integer types:
pthread_t pid;
pthread_create(&pid, NULL, (void *(*)(void *))foo, (void *)argument));
However, you'd better wrap your function into another, pthread-compatible one, then return a pointer to its return value (must be free()'d after use):
void *foo_wrapper(void *arg)
{
int a = *(int *)arg;
bool retval = foo(a);
bool *ret = malloc(sizeof(bool));
*ret = retval;
return ret;
}
then use:
pthread_t pid;
pthread_create(&pid, NULL, foo_wrapper, &a);
With this method, in the future you'll be able to call a function with arbitrary return or argument types.