资源描述:
《多核编程与并行计算实验报告(1)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、多核编程与并行计算实验报告姓名:日期:2014年4月20日实验一//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責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厶实验二//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;}实验三//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>«