多核编程与并行计算实验报告 (1)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

(此文档为word格式,下载后您可任意编辑修改!) 多核编程与并行计算实验报告

姓名:

日期:2014年 4月20日

实验一

exa1.cpp : Defines the entry point for the console application. #include"stdafx.()

{

int i=0;

_beginthread(ThreadFunc1,0,NULL);

_beginthread(ThreadFunc2,0,NULL);

Sleep(3000);

cout<<"end"<

return 0;

}

实验二

exa2.cpp : Defines the entry point for the console application. #include"stdafx. 0;

}

DWORD WINAPI FunTwo(LPVOID param){

while(true)

{

Sleep(1000);

cout<<"world! ";

}

return 0;

}

int main(int argc, char* argv[])

{

int input=0;

HANDLE >>input;

if(input==1)

{

ResumeThread( 0;

}

实验三

exa3.cpp : Defines the entry point for the console application. #include"stdafx. 0;

}

int main()

{

HANDLE 0;

}

实验四:

exa4.cpp : Defines the entry point for the console application. #include"stdafx.(int argc , char * argv[])

{

evRead = CreateEvent (NULL ,FALSE ,FALSE ,NULL) ;

evFinish = CreateEvent (NULL ,FALSE ,FALSE ,NULL) ;

_beginthread(ReadThread , 0 , NULL) ;

_beginthread(WriteThread , 0 , NULL) ;

WaitForSingleObject (evFinish,INFINITE) ;

cout<<"The Program is End"<

return 0 ;

}

实验五

exa5.cpp : Defines the entry point for the console application. #include"stdafx.[2] ;

CRITICAL_SECTION cs ;

void WithdrawThread1(LPVOID param)

{

EnterCriticalSection(&cs) ;

if ( total-90 >= 0)

{

total -= 90 ;

cout<<"You withdraw 90"<

}

else

cout<<"You do not (&cs) ;

SetEvent (evFin[0]) ;

}

void WithdrawThread2(LPVOID param)

{

EnterCriticalSection(&cs) ;

if ( total-20 >= 0)

{

total -= 20 ;

cout<<"You withdraw 20"<

}

else

cout<<"You do not (&cs) ;

LeaveCriticalSection(&cs) ;

SetEvent (evFin[1]) ;

}

int main(int argc , char * argv[])

{

evFin[0] = CreateEvent (NULL,FALSE,FALSE,NULL) ;

evFin[1] = CreateEvent (NULL,FALSE,FALSE,NULL) ;

InitializeCriticalSection(&cs) ;

_beginthread(WithdrawThread1 , 0 , NULL) ;

_beginthread(WithdrawThread2 , 0 , NULL) ;

WaitForMultipleObjects(2 ,evFin ,TRUE ,INFINITE) ;

DeleteCriticalSection(&cs) ;

cout<

return 0 ;

}

实验六:

exa6.cpp : Defines the entry point for the console application.

#include"stdafx. Mutex error!" << endl;

}

cout << "ThreadProc " << ThreadNumberTemp << " gets the mutex"<< endl;

ReleaseMutex( 0;

}

int main(int argc, char* argv[])

{

int i;

DWORD ID[THREAD_INSTANCE_NUMBER];

HANDLE 0;

}

}

for (i=0;i

{

0;

}

实验七

exa7.cpp : Defines the entry point for the console application.

#include"stdafx. Semaphore error!" << endl;

相关文档
最新文档