操作系统课程设计银行系统源代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
cout<<"第"<<number<<"个顾客"<<"已取号,号码:C"<<t<<endl;
LeaveCriticalSection(&print);
ReleaseMutex(mutex);//v(&mutex)
int seat_num=10;
HANDLE seat,SemaphorePrviate,SemaphorePublic,SemaphoreFinancial;//窗口信号量
HANDLE cSemaphorePrviate,cSemaphorePublic,cSemaphoreFinancial;//顾客信号量
EnterCriticalSection(&c_seat);
seat_num++;
LeaveCriticalSection(&c_seat);
}
return 0;
}
//理财叫号
DWORD WINAPI FinancialServiceThread(PVOID SemaphoreFinancialpv)
HANDLE mutex;
CRITICAL_SECTION c_seat; //临界区,用来限制同一时刻只能有一个线程来改变座位的数量
CRITICAL_SECTION print; //临界区,用来限制同一时刻只能有一个线程来访问资源,防止输出重叠
//对私叫号
DWORD WINAPI PrivateServiceThread(PVOID s1pv)
if(seat_num<=0)
{
EnterCriticalSection(&print);
cout<<"门外还剩"<<-seat_num<<"人在等待。"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&print);
cout<<"对顾客A"<<t<<"服务结束,服务时间:"<<ServeTime<<endl;
cout<<"该顾客选择继续等待,已有"<<-seat_num<<"顾客在门外等待"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&c_seat);
seat_num--;
LeaveCriticalSection(&c_seat);
cout<<"第"<<number<<"个顾客"<<"已取号,号码:B"<<t<<endl;
LeaveCriticalSection(&print);
ReleaseMutex(mutex);//v(&mutex)
ReleaseSemaphore(cSemaphorePublic,1,NULL);//v(&cSemaphorePublic)
LeaveCriticalSection(&print);
return 0;
}
//办理理财业务的顾客
DWORD WINAPI FinancialCustomer(PVOID c3pv)
{
srand((unsigned)time(0));
int n=rand()%2;
if( seat_num<=0&&n==1)
cout<<"该顾客选择继续等待,已有"<<-seat_num<<"顾客在门外等待"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&c_seat);
seat_num--;
LeaveCriticalSection(&c_seat);
LeaveCriticalSection(&c_seat);
}
return 0;
}
//办理对私服务顾客
DWORD WINAPI PrivateCustomer(PVOID c1pv)
{
srand((unsigned)time(NULL));
int n=rand()%2;
if(seat_num<=0&&n==1)
if(seat_num<=0)
{
EnterCriticalSection(&print);
cout<<"门外还剩"<<-seat_num<<"人在等待。"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&print);
cout<<"对顾客B"<<PublicNum<<"服务结束,服务时间:"<<ServeTime<<endl;
cout<<"该顾客选择了继续等待,已有"<<-seat_num<<"顾客在门外等待"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&c_seat);
seat_num--;
LeaveCriticalSection(&c_seat);
{
while(true)
{
srand((unsigned)time(NULL));
WaitForSingleObject(cSemaphorePrviate,INFINITE);
Sleep(1500);
EnterCriticalSection(&print);
cout<<"对私窗口叫号!"<<endl;
WaitForSingleObject(seat,INFINITE);//p(&seat)
WaitForSingleObject(mutex,INFINITE);//p(&mutex)
number++;
PrivateNum++;
int t=PrivateNum;
EnterCriticalSection(&print);
}
//对公叫号
DWORD WINAPI PublicServiceThread(PVOID s2pv)
{
while(true)
{
srand((unsigned)time(NULL));
WaitForSingleObject(cSemaphorePublic,INFINITE);//p(&cSemaphorePublic)
LeaveCriticalSection(&print);
ReleaseSemaphore(SemaphorePrviate,1,NULL);
EnterCriticalSection(&c_seat);
seat_num++;
LeaveCriticalSection(&c_seat);
}
return 0;
EnterCriticalSection(&print);
cout<<"顾客A"<<t<<"正在进入服务!"<<endl;
LeaveCriticalSection(&print);
Sleep(ServeTime);
ReleaseSemaphore(seat,1,NULL);//v(&seat)
seat_num++;
{
EnterCriticalSection(&print);
cout<<"等待室座位已满,该顾客选择离开!"<<endl;
LeaveCriticalSection(&print);
}
else if(seat_num<=0)
{
seat_num--;
EnterCriticalSection(&print);
LeaveCriticalSection(&print);
return 0;
}
//办理对公服务顾客
DWORD WINAPI PublicCustomer(PVOID c2pv)
{
srand((unsigned)time(0));
int n=rand()%2;
if( seat_num<=0&&n==1)
EnterCriticalSection(&print);
cout<<"顾客B"<<t<<"等待对公服务!"<<endl;
LeaveCriticalSection(&print);
int ServeTime=rand()%4000+500;
Sleep(ServeTime);
WaitForSingleObject(SemaphorePublic,INFINITE);//p(&SemaphorePublic)
##include<windows.h>
#include<ctime>
#include<iostream>
using namespace std;
#define Seat 10
#define Time 500//顾客来的最大间隔时间
int number = 0;//当前服务的顾客总数
int PrivateNum=0,PublicNum=0,FinancialNum=0; //取号数
WaitForSingleObject(seat,INFINITE);//p(&seat)
WaitForSingleObject(mutex,INFINITE);//p(&mutex)
number++;
PublicNum++;
int t=PublicNum;
EnterCriticalSection(&print);
{
EnterCriticalSection(&print);
cout<<"等待室座位已满,该顾客选择离开!"<<endl;
LeaveCriticalSection(&print);
}
else if(seat_num<=0)
{
seat_num--;
EnterCriticalSection(&print);
{
EnterCriticalSection(&print);
cout<<"等待室座位已满,该顾客选择离开!"<<endl;
LeaveCriticalSection(&print);
}
else if(seat_num<=0)
{
seat_num--;
EnterCriticalSection(&print);
cout<<"理财窗口叫号!"<<endl;
LeaveCriticalSection(&print);
ReleaseSemaphore(SemaphoreFinancial,1,NULL);//v(&SemaphoreFinancial)
EnterCriticalSection(&c_seat);
seat_num++;
{
while(true)
{
srand((unsigned)time(NULL));
WaitForSingleObject(cSemaphoreFinancial,INFINITE);//p(&cSemaphoreFinancial)
Sleep(1500);
EnterCriticalSຫໍສະໝຸດ Baiduction(&print);
EnterCriticalSection(&print);
cout<<"顾客B"<<t<<"正在进入服务!"<<endl;
LeaveCriticalSection(&print);
Sleep(ServeTime);
ReleaseSemaphore(seat,1,NULL);//v(&seat)
seat_num++;
EnterCriticalSection(&print);
cout<<"顾客A"<<t<<"等待对私服务!"<<endl;
LeaveCriticalSection(&print);
int ServeTime=rand()%4000+500;
Sleep(ServeTime);
WaitForSingleObject(SemaphorePrviate,INFINITE);//p(&SemaphorePrviate)
WaitForSingleObject(seat,INFINITE);//p(&seat)
WaitForSingleObject(mutex,INFINITE);//p(&muteprint)
number++;
FinancialNum++;
int t=FinancialNum;
EnterCriticalSection(&print);
Sleep(1500);
EnterCriticalSection(&print);
cout<<"对公窗口叫号!"<<endl;
LeaveCriticalSection(&print);
ReleaseSemaphore(SemaphorePublic,1,NULL);//v(&SemaphorePublic)
cout<<"第"<<number<<"个顾客"<<"已取号,号码:A"<<t<<endl;
LeaveCriticalSection(&print);
ReleaseMutex(mutex);//v(&mutex)
ReleaseSemaphore(cSemaphorePrviate,1,NULL);//v(&cSemaphorePrviate)
LeaveCriticalSection(&print);
ReleaseMutex(mutex);//v(&mutex)
int seat_num=10;
HANDLE seat,SemaphorePrviate,SemaphorePublic,SemaphoreFinancial;//窗口信号量
HANDLE cSemaphorePrviate,cSemaphorePublic,cSemaphoreFinancial;//顾客信号量
EnterCriticalSection(&c_seat);
seat_num++;
LeaveCriticalSection(&c_seat);
}
return 0;
}
//理财叫号
DWORD WINAPI FinancialServiceThread(PVOID SemaphoreFinancialpv)
HANDLE mutex;
CRITICAL_SECTION c_seat; //临界区,用来限制同一时刻只能有一个线程来改变座位的数量
CRITICAL_SECTION print; //临界区,用来限制同一时刻只能有一个线程来访问资源,防止输出重叠
//对私叫号
DWORD WINAPI PrivateServiceThread(PVOID s1pv)
if(seat_num<=0)
{
EnterCriticalSection(&print);
cout<<"门外还剩"<<-seat_num<<"人在等待。"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&print);
cout<<"对顾客A"<<t<<"服务结束,服务时间:"<<ServeTime<<endl;
cout<<"该顾客选择继续等待,已有"<<-seat_num<<"顾客在门外等待"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&c_seat);
seat_num--;
LeaveCriticalSection(&c_seat);
cout<<"第"<<number<<"个顾客"<<"已取号,号码:B"<<t<<endl;
LeaveCriticalSection(&print);
ReleaseMutex(mutex);//v(&mutex)
ReleaseSemaphore(cSemaphorePublic,1,NULL);//v(&cSemaphorePublic)
LeaveCriticalSection(&print);
return 0;
}
//办理理财业务的顾客
DWORD WINAPI FinancialCustomer(PVOID c3pv)
{
srand((unsigned)time(0));
int n=rand()%2;
if( seat_num<=0&&n==1)
cout<<"该顾客选择继续等待,已有"<<-seat_num<<"顾客在门外等待"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&c_seat);
seat_num--;
LeaveCriticalSection(&c_seat);
LeaveCriticalSection(&c_seat);
}
return 0;
}
//办理对私服务顾客
DWORD WINAPI PrivateCustomer(PVOID c1pv)
{
srand((unsigned)time(NULL));
int n=rand()%2;
if(seat_num<=0&&n==1)
if(seat_num<=0)
{
EnterCriticalSection(&print);
cout<<"门外还剩"<<-seat_num<<"人在等待。"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&print);
cout<<"对顾客B"<<PublicNum<<"服务结束,服务时间:"<<ServeTime<<endl;
cout<<"该顾客选择了继续等待,已有"<<-seat_num<<"顾客在门外等待"<<endl;
LeaveCriticalSection(&print);
}
EnterCriticalSection(&c_seat);
seat_num--;
LeaveCriticalSection(&c_seat);
{
while(true)
{
srand((unsigned)time(NULL));
WaitForSingleObject(cSemaphorePrviate,INFINITE);
Sleep(1500);
EnterCriticalSection(&print);
cout<<"对私窗口叫号!"<<endl;
WaitForSingleObject(seat,INFINITE);//p(&seat)
WaitForSingleObject(mutex,INFINITE);//p(&mutex)
number++;
PrivateNum++;
int t=PrivateNum;
EnterCriticalSection(&print);
}
//对公叫号
DWORD WINAPI PublicServiceThread(PVOID s2pv)
{
while(true)
{
srand((unsigned)time(NULL));
WaitForSingleObject(cSemaphorePublic,INFINITE);//p(&cSemaphorePublic)
LeaveCriticalSection(&print);
ReleaseSemaphore(SemaphorePrviate,1,NULL);
EnterCriticalSection(&c_seat);
seat_num++;
LeaveCriticalSection(&c_seat);
}
return 0;
EnterCriticalSection(&print);
cout<<"顾客A"<<t<<"正在进入服务!"<<endl;
LeaveCriticalSection(&print);
Sleep(ServeTime);
ReleaseSemaphore(seat,1,NULL);//v(&seat)
seat_num++;
{
EnterCriticalSection(&print);
cout<<"等待室座位已满,该顾客选择离开!"<<endl;
LeaveCriticalSection(&print);
}
else if(seat_num<=0)
{
seat_num--;
EnterCriticalSection(&print);
LeaveCriticalSection(&print);
return 0;
}
//办理对公服务顾客
DWORD WINAPI PublicCustomer(PVOID c2pv)
{
srand((unsigned)time(0));
int n=rand()%2;
if( seat_num<=0&&n==1)
EnterCriticalSection(&print);
cout<<"顾客B"<<t<<"等待对公服务!"<<endl;
LeaveCriticalSection(&print);
int ServeTime=rand()%4000+500;
Sleep(ServeTime);
WaitForSingleObject(SemaphorePublic,INFINITE);//p(&SemaphorePublic)
##include<windows.h>
#include<ctime>
#include<iostream>
using namespace std;
#define Seat 10
#define Time 500//顾客来的最大间隔时间
int number = 0;//当前服务的顾客总数
int PrivateNum=0,PublicNum=0,FinancialNum=0; //取号数
WaitForSingleObject(seat,INFINITE);//p(&seat)
WaitForSingleObject(mutex,INFINITE);//p(&mutex)
number++;
PublicNum++;
int t=PublicNum;
EnterCriticalSection(&print);
{
EnterCriticalSection(&print);
cout<<"等待室座位已满,该顾客选择离开!"<<endl;
LeaveCriticalSection(&print);
}
else if(seat_num<=0)
{
seat_num--;
EnterCriticalSection(&print);
{
EnterCriticalSection(&print);
cout<<"等待室座位已满,该顾客选择离开!"<<endl;
LeaveCriticalSection(&print);
}
else if(seat_num<=0)
{
seat_num--;
EnterCriticalSection(&print);
cout<<"理财窗口叫号!"<<endl;
LeaveCriticalSection(&print);
ReleaseSemaphore(SemaphoreFinancial,1,NULL);//v(&SemaphoreFinancial)
EnterCriticalSection(&c_seat);
seat_num++;
{
while(true)
{
srand((unsigned)time(NULL));
WaitForSingleObject(cSemaphoreFinancial,INFINITE);//p(&cSemaphoreFinancial)
Sleep(1500);
EnterCriticalSຫໍສະໝຸດ Baiduction(&print);
EnterCriticalSection(&print);
cout<<"顾客B"<<t<<"正在进入服务!"<<endl;
LeaveCriticalSection(&print);
Sleep(ServeTime);
ReleaseSemaphore(seat,1,NULL);//v(&seat)
seat_num++;
EnterCriticalSection(&print);
cout<<"顾客A"<<t<<"等待对私服务!"<<endl;
LeaveCriticalSection(&print);
int ServeTime=rand()%4000+500;
Sleep(ServeTime);
WaitForSingleObject(SemaphorePrviate,INFINITE);//p(&SemaphorePrviate)
WaitForSingleObject(seat,INFINITE);//p(&seat)
WaitForSingleObject(mutex,INFINITE);//p(&muteprint)
number++;
FinancialNum++;
int t=FinancialNum;
EnterCriticalSection(&print);
Sleep(1500);
EnterCriticalSection(&print);
cout<<"对公窗口叫号!"<<endl;
LeaveCriticalSection(&print);
ReleaseSemaphore(SemaphorePublic,1,NULL);//v(&SemaphorePublic)
cout<<"第"<<number<<"个顾客"<<"已取号,号码:A"<<t<<endl;
LeaveCriticalSection(&print);
ReleaseMutex(mutex);//v(&mutex)
ReleaseSemaphore(cSemaphorePrviate,1,NULL);//v(&cSemaphorePrviate)