Using pthread to perform matrix multiplication Using pthread to perform matrix multiplication unix unix

Using pthread to perform matrix multiplication


I don't know if this is the cause of your problem but:

    pthread_create(&p[j],NULL,mult_thread,&j);

is definitely broken. You are passing in the address of j &j. So each thread will get a random value 0 <= starting_row <= 9, when it actually starts. Probably better to just pass in (void*)j and get it out with (int)j.

You're also never initialising res_mat, but IIRC it'll get initialised anyway.

EDIT:The reason that the value of starting_row is random, is the j goes through all the numbers between 0 and 9 between the thread being started, and it being joined.So the thread will be started at some random point between those two, and will pick up the value of j at that point.


You are passing a pointer to j to the thread function. The value of j may have changed when the thread accesses it. Just pass (void *)j and change the cast in the thread function to starting_row = (int)t; .