/* Suzuki Creating threads to multiply a matrix */ #include #include using namespace std; // given in book #define M 3 #define K 2 #define N 3 // given in book // matrix to be multiplied int A[M][K] = {{1,4},{2,5},{3,6}}; int B[K][N] = {{8,7,6},{5,4,3}}; int C[M][N]; // matrix result // given in book struct V { int i, j; }; // given in book // THREAD DWORD WINAPI multiply( LPVOID param) { // multiply col and column here struct V *data = (struct V *) malloc(sizeof(struct V)); data = ((struct V*) param); // set result matrix location to zero C[data->i][data->j] = 0; // calculate the values of the result for( int x =0; x< K; x++) C[data->i][data->j] += ( A[data->i][x] * B[x][data->j] ); return 0; }; int main( int manyArgs, char * args[]) { HANDLE h[M*N]; // 4 threads DWORD id[M*N]; for( int i=0; i< M; i++) // col { for( int j=0; j< N; j++) // column { struct V *data = (struct V*) malloc(sizeof(struct V)); data->i = i; data->j = j; h[i*N + j] = CreateThread( NULL, 0, multiply, data, 0, &id[i*N + j]); if(h[i*N + j] == NULL) cout <<"OOOppppsssss"<