欢迎来到天天文库
浏览记录
ID:59195762
大小:31.50 KB
页数:8页
时间:2020-09-10
《操作系统课程设计银行系统源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、##include#include#includeusingnamespacestd;#defineSeat10#defineTime500//顾客来的最大间隔时间intnumber=0;//当前服务的顾客总数intPrivateNum=0,PublicNum=0,FinancialNum=0;//取号数intseat_num=10;HANDLEseat,SemaphorePrviate,SemaphorePublic,SemaphoreFinancial;//窗口信号量HANDLEc
2、SemaphorePrviate,cSemaphorePublic,cSemaphoreFinancial;//顾客信号量HANDLEmutex;CRITICAL_SECTIONc_seat;//临界区,用来限制同一时刻只能有一个线程来改变座位的数量CRITICAL_SECTIONprint;//临界区,用来限制同一时刻只能有一个线程来访问资源,防止输出重叠//对私叫号DWORDWINAPIPrivateServiceThread(PVOIDs1pv){while(true){srand((unsigned)time(NULL));Wait
3、ForSingleObject(cSemaphorePrviate,INFINITE);Sleep(1500);EnterCriticalSection(&print);cout<<"对私窗口叫号!"<4、APIPublicServiceThread(PVOIDs2pv){while(true){srand((unsigned)time(NULL));WaitForSingleObject(cSemaphorePublic,INFINITE);//p(&cSemaphorePublic)Sleep(1500);EnterCriticalSection(&print);cout<<"对公窗口叫号!"<5、L);//v(&SemaphorePublic)EnterCriticalSection(&c_seat);seat_num++;LeaveCriticalSection(&c_seat);}return0;}//理财叫号DWORDWINAPIFinancialServiceThread(PVOIDSemaphoreFinancialpv){while(true){srand((unsigned)time(NULL));WaitForSingleObject(cSemaphoreFinancial,INFINITE);//p(&cSemap6、horeFinancial)Sleep(1500);EnterCriticalSection(&print);cout<<"理财窗口叫号!"<7、APIPrivateCustomer(PVOIDc1pv){srand((unsigned)time(NULL));intn=rand()%2;if(seat_num<=0&&n==1){EnterCriticalSection(&print);cout<<"等待室座位已满,该顾客选择离开!"<8、num<<"顾客在门外等待"<
4、APIPublicServiceThread(PVOIDs2pv){while(true){srand((unsigned)time(NULL));WaitForSingleObject(cSemaphorePublic,INFINITE);//p(&cSemaphorePublic)Sleep(1500);EnterCriticalSection(&print);cout<<"对公窗口叫号!"<5、L);//v(&SemaphorePublic)EnterCriticalSection(&c_seat);seat_num++;LeaveCriticalSection(&c_seat);}return0;}//理财叫号DWORDWINAPIFinancialServiceThread(PVOIDSemaphoreFinancialpv){while(true){srand((unsigned)time(NULL));WaitForSingleObject(cSemaphoreFinancial,INFINITE);//p(&cSemap6、horeFinancial)Sleep(1500);EnterCriticalSection(&print);cout<<"理财窗口叫号!"<7、APIPrivateCustomer(PVOIDc1pv){srand((unsigned)time(NULL));intn=rand()%2;if(seat_num<=0&&n==1){EnterCriticalSection(&print);cout<<"等待室座位已满,该顾客选择离开!"<8、num<<"顾客在门外等待"<
5、L);//v(&SemaphorePublic)EnterCriticalSection(&c_seat);seat_num++;LeaveCriticalSection(&c_seat);}return0;}//理财叫号DWORDWINAPIFinancialServiceThread(PVOIDSemaphoreFinancialpv){while(true){srand((unsigned)time(NULL));WaitForSingleObject(cSemaphoreFinancial,INFINITE);//p(&cSemap
6、horeFinancial)Sleep(1500);EnterCriticalSection(&print);cout<<"理财窗口叫号!"<7、APIPrivateCustomer(PVOIDc1pv){srand((unsigned)time(NULL));intn=rand()%2;if(seat_num<=0&&n==1){EnterCriticalSection(&print);cout<<"等待室座位已满,该顾客选择离开!"<8、num<<"顾客在门外等待"<
7、APIPrivateCustomer(PVOIDc1pv){srand((unsigned)time(NULL));intn=rand()%2;if(seat_num<=0&&n==1){EnterCriticalSection(&print);cout<<"等待室座位已满,该顾客选择离开!"<8、num<<"顾客在门外等待"<
8、num<<"顾客在门外等待"<
此文档下载收益归作者所有