When calling pthread_create()
you need to pass the address of a function of type void *(*)(void *)
. What the code does is calling a function there so its result is getting passed to pthread_create()
.
Change this line
pthread_create(&tid, &attr, matrixCalc(threadCount), NULL);
to become
pthread_create(&tid, &attr, matrixCalc, NULL);
or
pthread_create(&tid, &attr, &matrixCalc, NULL);
which in fact is the same.
As already mentioned above the thread function needs to be declared as void *(*)(void *)
.
So change this
void *matrixCalc(threadCount)
will will become this
void * matrixCalc(void *)
As the code seems to try to spawn off multiple threads and all should be joined perpare room to store the several pthread-ids.
This could for example be done using an array like this:
pthread_t tid[numberOfThreads] = {0};
Then create the thread like this:
pthread_create(&tid[i], &attr, matrixCalc, NULL);
To passed the thread number (counter i
) down to the thread also give it room by defining
int thread_counts[numberOfThreads] = {0};
assign it and pass it as 4th parameter on the thread's creation:
thread_counts[i] = i;
pthread_create(&tid[i], &attr, matrixCalc, &thread_Counts[i]);
Down in the thread function then get it by modifying
void *matrixCalc(threadCount)
{
int i, j, sum, tempNum, currentRow;
currentRow = threadCount;
...
like this:
void * matrixCalc(void * pv)
{
int i, j, sum, tempNum, currentRow;
currentRow = *((int*) pv);
...
Finally to join all thread replace the single call to pthread_join()
by a loop:
for (i = 0; i < numberOfThreads; ++i)
{
pthread_join(tid[i], NULL);
}