📄 test.cpp
字号:
// project created on 09-3-29 at 下12:03#include <stdio.h>#include <pthread.h>const int row=4;const int column1=5;const int column2=4;int sz1[row][column1]={1,2,3,4,5,2,3,4,5,6,3,4,5,6,7,4,5,6,7,8};
int sz2[column1][column2]={1,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7,5,6,7,8};
int szRes[row][column2]={0};
const int threadNumber=row*column2;struct IANDJ{int i;int j;};
void * funCal(void * arg)
{ IANDJ *temp=(IANDJ *)arg; for(int i=0;i<column1;i++)
szRes[temp->i][temp->j]+=sz1[temp->i][i]*sz2[i][temp->j];
} int main (int argc, char *argv[]){ IANDJ *iandjs[threadNumber]; for(int i=0;i<threadNumber;i++) iandjs[i]=new IANDJ(); pthread_t hThread[threadNumber]; for (int i = 0; i < row; i++) { for(int j=0;j< column2;j++) { iandjs[i*row+j]->i=i; iandjs[i*row+j]->j=j; pthread_create(&hThread[i*row+j], NULL, funCal,iandjs[i*4+j]); } } for (int i = 0; i < threadNumber; i++) pthread_join(hThread[i], NULL); for(int i=0;i<row;i++) { for(int j=0;j<column2;j++) printf("%d ",szRes[i][j]); printf("\n"); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -