I'm working on a project that is supposed to create a couple of threads, each of which call a function that prints a message when the thread has finished executing.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
void* match(int id, int number){
for(;;){
int random = 1 + (rand()%9999);
if(random == number) break;
}
printf("Thread number %d has completed.", id);
}
int main (int argc, char *argv[]){
int conv = atoi(argv[1]);
pthread_t th[10];
int i;
for (i = 0; i < 10; i++){
if(pthread_create(th+i, NULL, &match(i, conv), NULL)!=0){
perror("Failed to create thread");
return 1;
}
for (i = 0; i < 10; i++){
if (pthread_join(th[i], NULL)!= 0){
return 2;
}
}
return 0;
}
The problem is that trying to pass arguments to the function pointer gives me an error "lvalue required as unary '&' operand". It looks like pthread_create only accept a function pointer with a specific signature for its third argument. What do I need to change to make this work?