資源描述:
《多核編程與并行計(jì)算實(shí)驗(yàn)報(bào)告(1)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、多核編程與并行計(jì)算實(shí)驗(yàn)報(bào)告姓名:日期:2014年4月20日實(shí)驗(yàn)一//exa1.cpp:Definestheentrypointfortheconsoleapplication.#inelude"stdafx.h"#inelude#inelude#inelude#ineludeusingnamespacestd;voidThreadFuncl(PVOIDparam){whi1e(1){Sleep(1000);cout<<,,ThisisThreadFuncr,?ondl;}}vo
2、idThreadFunc2(PVOIDparam)Iwhile仃){Sleep(1000):cout<<"ThisisThreadFunc2,z?endl;}}intmain(){inti=0;_beginthread(ThreadFuncl,0,NULL);_beginthread(ThreadFunc2,0,NULL);Sleep(3000);cout<<,,end,,?endl;return0;J"??>tao>vnt>mqp.32責(zé)C:fIVDOVSsysteB32cBd.exefinclud?*rtdaf
3、x.h#finclude>include?includefineludena:-void-voidwhileiS]mt-be?u豪l/l(fit2WgXC^guiiQQQisThrwadFunclThisisThreadFunc2isThreadFunc2ThisisThreadFunclisThrwadFunclThicisThrvadFunc2iniRi■l?U?iradfl0—9irr?v?ftfs、叨O厶實(shí)驗(yàn)二//exa2.cpp:Definestheentrypointfortheconsoleapplication.//#inelude"stda
4、fx.h"#inelude#includeusingnamespacestd;DWORDWTNAPTFunOne(LPVOTDparam){while(true){Sleep(lOOO);cout<<,,hello!”;}return0;}DWORDW1NAP1FunTwo(LPV01Dparam){while(true){Sleep(1000);cout<<,zworld!}return0;intmain(iniargc,char*argv[]){intinput=0;HANDLEhancll=CrcatcThr
5、ead(NULL,0,FunOnc,(void*)&input,CREATE_SUSPENDED,NULL);HANDLEhand2=CreateThread(NULL,0,FunTwo,(void*)&input,CREATE_SUSPENDED,NULL);while(true){cin?input;if(input==l){ResumeThread(handl);ResuinoThread(hand2);}else{SuspendThread(handl);SuspendThrcad(hand2);}};TerminateThread(handl,1)
6、;TerminateThread(hand2,1);return0;}實(shí)驗(yàn)三//exa3?cpp:Definestheentrypointfortheconsoleapplication.//#inelude"sldafx.h"#inelude〈windows?h〉#ineludeusingnamespacestd;intglobalvar=false;DWORDWINAPIThreadFunc(LPVOIDpParam){cout<<,,ThreadFunc"〈〈endl;Sleep(200);globalvar=true;return
7、0;}intiiminO{HANDLEhthread=CreateThread(NULL,0,ThreadFunc,NULL,0,NULL);if(!hthread){cout<irc?ItrraMflf」■l?U■Ihr#Adrbread【hi*eadIhr
8、cadrhveAdrhv^AriIbreadrh>?