/**ORDINARYCRAZY**/
#include <stdio.h>
#define _GNU_SOURCE
#include <unistd.h>
#include <pthread.h>
#include <sys/syscall.h>
#include <stdlib.h>
#define M 3
#define K 2
#define N 3
typedef struct{
int row,column;
}parameter;
int Matrix_A[M][K] = {
{1,4},{2,5},{3,6}};
int Matrix_B[K][N] = {
{8,7,6},{5,4,3}};
int Matrix_C[M][N];
void* worker(void* para){
parameter* par = (parameter*)para;
int i,sum = 0;
for(i = 0;i < K;i++) sum += Matrix_A[par->row][i] * Matrix_B[i][par->column];
printf("POSIX Thread: %ld ,kernel Thread: %ld :C[%d][%d] = %d\n",\
pthread_self(),syscall(SYS_gettid),par->row,par->column,sum);
pthread_exit(0);
}
int main(){
int i,j;
pthread_t workers[M][N];
pthread_attr_t attr;
/* get the default attributes */
pthread_attr_init(&attr);
for(i = 0;i <
Pthread 多线程矩阵乘法
最新推荐文章于 2022-08-14 23:10:26 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)