欢迎来到天天文库
浏览记录
ID:30844299
大小:101.55 KB
页数:7页
时间:2019-01-03
《操作系统课程设计银行系统源代码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、##include#includc#includeusingnamespacestd;#defineSeat10#dcfincTime500〃顾客来的鼓大间隔时间intnumber=0;〃当前服务的顾客总数intPrivateNum=O,PublicNum=O,FinancialNum=O;〃収号数intseat_num二10;HANDLEseat,SemaphorePrviate,SemaphorePublic,SemaphoreFinancial;//窗口信号量HANDLEcSemaphorePrviate,cSemapho
2、rePublic,cSemaphoreFinancial;〃顾客信号量HANDLEmutex;CR1TICAL_SECTIONc_seat;〃临界区,用來限制同一时刻只能冇一个线程來改变座位的数量CRITICAL_SECTIONprint;〃临界区,用來限制同一时刻只能有一个线程來访问资源,防止输出重叠〃对私叫号DWORDWINAPIPrivateServiceThread(PVOIDslpv){while(true){srand((unsigned)time(NULL));WaitForSingleObject(cSemaphorePrviate,INFINITE);Sleep(1
3、500);EnterCriticalSection(&print);cout«"对私窗口叫号!"«endl;LcavcCriticalScction(&print);ReleaseSemaphore(SemaphorePrviate,l,NULL);EnterCriticalSection(&c_seat);seat_num++;LeaveCriticalSection(&c_seat);}return0;}〃对公叫号DWORDWINAPIPublicServiceThread(PVOIDs2pv){while(true){srand((unsigned)time(NULL));Wa
4、itForSingleObject(cSemaphorePublic,INFINITE);//p(&cSemaphorePublic)Slccp(1500);EnterCriticalSection(&print);cout«u对公窗口叫号!n«endl;LeaveCriticalSection(&print);ReleaseSemaphorc(ScmaphorcPublic丄NULL);//v(&SemaphorePublic)EnterCriticalSection(&c_seat);seat_num++;LeaveCriticalSection(&c_seat);rctum0;
5、}〃理财叫号DWORDWINAPIFinancialServiceThread(PVOIDSemaphoreFinancialpv){whilc(truc)srand((unsigned)time(NULL));WaitForSingleObject(cSemaphoreFinancial,INFINlTE);//p(&cSemaphoreFinancial)Sleep(1500);EntcrCriticalScction(&print);cout«H理财窗口叫号!M«endl;LeaveCriticalSection(&p「int);ReleaseSemaphore(Semapho
6、reFinancial,1,NULL);//v(&SemaphoreFinancial)EnterCriticalSection(&c_seat);seat_num++;LeaveCriticalSection(&c_seat);return0;}〃办理对私服务顾客DWORDWINAPIPrivateCustomer(PVOIDclpv){srand((unsigned)time(NULL));intn=rand()%2;if(scat_num<=0&&n二二1)EnterCriticalSection(&print);cout«"等待窣座位已满,该顾客选择离开!u«endl;Lea
7、veCriticalSection(&print);elseif(seat_num<=0){seat_num-;EnterCriticalSection(&print);cout«n该顾客选择了继续等待,已Wn«-seat_num«n顾客在门外等待”《endl;LeaveCriticalSection(&print);EntcrCriticalScction(&c_seat);seat_num~;LeaveCriticalSection(&c_seat);
此文档下载收益归作者所有