Your code contains minor error, but the logic is correct, don't worry.
I downloaded the code and tested it on my machine, so please note the following:
This line should be written this way...
pthread_create(&threads[i],NULL, matrixMul, &i);
Because according to the specs of pthread library that pthread_create
should take void pointer to the runner function and void pointer to the parameter. You don't need to add (void *)
because you already declared your runner function matrixMul
as void *
.
Your primary error here was (void) &i
and it should be &i
only as you already delcaired this parameter as void *
in the runner function's prototype. You shall too pass the runner function like this &matrixMul
.
Some other notes: "Code Review"
- You shouldn't put your logic in the else statement, you can simply after
printf("Dimensions ERRORR! ");
writeexit(-1);
because this is basically what you do if the dimensions error. - Check for the return value (status) of
pthread_create
andpthread_join