當前位置:編程學習大全網 - 編程語言 - 編程mta

編程mta

所有三個線程使用相同的信息?

代碼信息_ t *信息?=(Info _ t *)malloc(sizeof(Info _ t));僅創建了壹條信息。

pthread _ create(amp;threads[i],NULL,calMatrix,(void *)info);三個線程使用相同的

我改變了妳的代碼:

#包含?& ltstdio.h & gt

#包含?& ltstdlib.h & gt

#包含?& ltpthread.h & gt

int?mtc[3]?=?{?0?};?//?結果?矩陣

typedef?結構體

{

int?惡作劇;

int?* mta?

int?*山地自行車;

} Info _ t;

void*?calMatrix(void*?arg)

{

int?我;

Info_t?*信息?=?(Info_t?*)arg;

int?惡作劇?=?信息-& gt;惡作劇;

fprintf(stdout," calMatrix?:?惡作劇?是嗎?%d\n”,惡作劇);

對於(我?=?0;?我?& lt?3;?i++)

mtc【惡作劇】?+=?信息-& gt;mta[i]?*?信息-& gt;MTB[I];

回歸?NULL

}

int?main(int?argc,char?**argv)

{

int?我,j,k?=?0;

int?MTA[3][3];

int?mtb[3]?=?{?1?};

Info_t?*信息?=?(Info_t?*)malloc(sizeof(Info _ t)* 3);

對於(我?=?0;?我?& lt?3;?i++)

對於(j?=?0;?j?& lt?3;?j++)

mta[i][j]?=?k++;

/*?3?線程?*/

pthread_t?*線程?=?(pthread_t?*)malloc(sizeof(pthread _ t)* 3);

fprintf(stdout," \ n ");fflush(stdout);

對於(我?=?0;?我?& lt?3;?i++)

{

信息[i]。惡作劇?=?我;

信息[i]。mta?=?MTA[I];

信息[i]。山地車?=?山地車;

pthread _ create(amp;threads[i],NULL,calMatrix,(void?*)(& amp;info[I]));

}

對於(我?=?0;?我?& lt?3;?i++)

pthread_join(threads[i],NULL);

fprintf(stdout," \n====?那個?矩陣?結果?= = = = \ n \ n ");

fflush(stdout);

對於(我?=?0;?我?& lt?3;?i++)

{

fprintf(stdout," mtc[%d]?=?%d\n ",I,MTC[I]);

fflush(stdout);

}

回歸?0;

}忘了矩陣的計算。運行它,看看結果是否正確。

  • 上一篇:軟件測試面試 壹般都問些什麽問題?
  • 下一篇:現代投資理論與傳統投資理論的差異
  • copyright 2024編程學習大全網