2、(NULL,0,Thread1,&qw2,0,NULL);HANDLEGarlandless[2]={ThreadHandle1,ThreadHandle2};Multiplepoinding(2,Garlandless,TRUE,INFINITE);Printer(“j=%d”,j)return0;}第二题:利用Win32API的多线程函数统计一个文件里的数字的个数和字母的个数;#includeHANDLEg_Ventress;//aglobalhandletoevent.voidOpenFileAndReadContentsInt
3、oMemory(){printf("OpenFileandReadcontentsintomemory");}DWORDWINAPIWordCount(PVOIDpvParam){//Waituntilthefile'sdataisinmemory.WaitForSingleObject(g_hEvent,INFINITE);//Accessthememoryblock.printf("0:wordcount");SetEvent(g_hEvent);//自动return(0);DWORDWINAPIfigureCount(PVOIDpvParam
4、){//Waituntilthefile'sdataisinmemory.WaitForSingleObject(g_hEvent,INFINITE);//Accessthememoryblock.printf("0:figurecount");SetEvent(g_hEvent);//自动return(0);}intmain(){//g_hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);//人工重置g_hEvent=CreateEvent(NULL,FALSE,FALSE,NULL);//自动重置HANDLEhThre
5、ad[2];DWORDdwThreadID[2];hThread[0]=CreateThread(NULL,0,WordCount,NULL,0,&dwThreadID[0]);hThread[1]=CreateThread(NULL,0,figurecount,NULL,0,&dwThreadID[1]);OpenFileAndReadContentsIntoMemory();//Allowall2threadstoaccessthememory.SetEvent(g_hEvent);WaitForMultipleObjects(2,//countofo
6、bjectshThread,//threadhandleTRUE,//waitforallINFINITE);//timeoutintervalprintf("mainthreadexit");getchar();return0;}第三题:利用OpenMP,计算1+2+3+。。+10000intcounter=0;#pragmaompthreadprivate(counter)voidinc_counter(){counter++;}intmain(){#pragmaompparallelfor(inti=0;i<10000;i++)inc_count
7、er();printf(“counter=%d”,counter);}intglobal=0;#pragmaompthreadprivate(global)intmain(){global=10000;#pragmaompparallelcopyin(global){printf(“global=%d”,global);global=omp_get_thread_num();}printf(“global=%d”,global);printf(“parallelagain”);#pragmaompparallelprintf(“global
8、=%d”,global);}第四题:利用OpenMP,统计一个