the prototype of pthread_create is
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
As the arg parameter is a void* you can simply write
pthread_create(&th,NULL,function_call, G);
However, it the function_call(), you will need to cast you arg parameter to the real type.
either:
function_call(void *arg)
{
graph *tmp_G;
tmp_G = arg;
// then I use tmp_G as G
}
or
((graph *)arg)->the_field_of_G;
Then you will be able to use you parameter as you need.
If you want to give more then one parameter to you function, you simply have to create a new structure that will contain all your parameters, then cast it as above to use them in your function_call().
here is an example :
typedef struct s_my_function_call_arg
{
graph *G;
int arg2;
char *arg3;
} t_my_function_call_arg;
C
rather thanC++
? – outis Mar 18 '15 at 5:30