NameFile = PictureDir + AnsiString("\\money.jpg");
BankForm->Terminal1->Picture->LoadFromFile(NameFile.c_str());
hKassa2 = CreateThread(NULL,0,Potok2,NULL,0,NULL);
NameFile = PictureDir + AnsiString("\\money.jpg");
BankForm->Terminal2->Picture->LoadFromFile(NameFile.c_str());
break;
case 2:
//Стартуем вторичный поток
if(!hKassa1) hKassa1 = CreateThread(NULL,0,Potok1,NULL,0,NULL);
NameFile = PictureDir + AnsiString("\\money.jpg");
BankForm->Terminal1->Picture->LoadFromFile(NameFile.c_str());
if(!hKassa2) hKassa2 = CreateThread(NULL,0,Potok2,NULL,0,NULL);
NameFile = PictureDir + AnsiString("\\money.jpg");
BankForm->Terminal2->Picture->LoadFromFile(NameFile.c_str());
hKassa3 = CreateThread(NULL,0,Potok3,NULL,0,NULL);
NameFile = PictureDir + AnsiString("\\money.jpg");
BankForm->Terminal3->Picture->LoadFromFile(NameFile.c_str());
break;
}
}
//---------------------------------------------------------------------------
DWORD WINAPI TBankForm::Potok1(LPVOID param)
{
//обслуживаем клиента
while(1)
{
if(in_queue > 0 & !pause1)
{
EnterCriticalSection(&Sect1);
// посылаем в окно сообщение
in_queue--;
BankForm->Edit1->Text = in_queue;
LeaveCriticalSection(&Sect1);
//Определяем время обслуживания
n1 = 2;
n1 = random(7);
BankForm->Time1->Caption = n1;
BankForm->T1Label->Caption = "Занят";
Sleep(n1*MAX_TIME);
}
else
{
if(!pause1)
{
BankForm->T1Label->Caption = "Свободен";
}
else
{
BankForm->T1Label->Caption = "Перерыв";
}
}
}
return(0);
}
//---------------------------------------------------------------------------
DWORD WINAPI TBankForm::Potok2(LPVOID param)
{
while(1)
{
if(in_queue > 0 & !pause2 )
{
EnterCriticalSection(&Sect1);
in_queue--;
BankForm->Edit1->Text = in_queue;
LeaveCriticalSection(&Sect1);
n2 = 2;
n2 = random(7);
BankForm->Time2->Caption = n2;
BankForm->T2Label->Caption = "Занят";
Sleep(n2*MAX_TIME);
}
else
{
if(!pause2)
{
BankForm->T2Label->Caption = "Свободен";
}
else
{
BankForm->T2Label->Caption = "Перерыв";
}
}
}
return(0);
}
//---------------------------------------------------------------------------
DWORD WINAPI TBankForm::Potok3(LPVOID param)
{
while(1)
{
if(in_queue > 0 & !pause3)
{
EnterCriticalSection(&Sect1);
in_queue--;
BankForm->Edit1->Text = in_queue;
LeaveCriticalSection(&Sect1);
n3 = 2;
n3 = random(7);
BankForm->Time3->Caption = n3;
BankForm->T3Label->Caption = "Занят";
Sleep(n3*MAX_TIME);
}
else
{
if(!pause3)
{
BankForm->T3Label->Caption = "Свободен";
}
else
{
BankForm->T3Label->Caption = "Перерыв";
}
}
}
return(0);
}
//---------------------------------------------------------------------------
void __fastcall TBankForm::FormDestroy(TObject *Sender)
{
if(hKassa1) TerminateThread(hKassa1,0);
if(hKassa2) TerminateThread(hKassa2,0);
if(hKassa3) TerminateThread(hKassa3,0);
}
//---------------------------------------------------------------------------
void __fastcall TBankForm::FormCreate(TObject *Sender)
{
InitializeCriticalSection(&Sect1);
Timer1->Interval = MAX_TIME;
WorkDir = ExtractFileDir(ParamStr(0));
PictureDir = WorkDir + AnsiString("\\pictures");
}
//---------------------------------------------------------------------------
void __fastcall TBankForm::Button1Click(TObject *Sender)
{
Close() ;
}
//---------------------------------------------------------------------------
void __fastcall TBankForm::PauseBtn1Click(TObject *Sender)
{
if(!pause1)
{
pause1 = true;
PauseBtn1->Caption = "Продолжить";
NameFile = PictureDir + AnsiString("\\coffee.jpg");
BankForm->Terminal1->Picture->LoadFromFile(NameFile.c_str());
}
else
{
pause1 = false;
PauseBtn1->Caption = "Пауза";
NameFile = PictureDir + AnsiString("\\money.jpg");
BankForm->Terminal1->Picture->LoadFromFile(NameFile.c_str());
}
}
//---------------------------------------------------------------------------
void __fastcall TBankForm::PauseBtn2Click(TObject *Sender)
{
if(!pause2)
{
pause2 = true;
PauseBtn2->Caption = "Продолжить";
NameFile = PictureDir + AnsiString("\\coffee.jpg");
BankForm->Terminal2->Picture->LoadFromFile(NameFile.c_str());
}
else
{
pause2 = false;
PauseBtn2->Caption = "Пауза";
NameFile = PictureDir + AnsiString("\\money.jpg");
BankForm->Terminal2->Picture->LoadFromFile(NameFile.c_str());
}
}
//---------------------------------------------------------------------------
void __fastcall TBankForm::PauseBtn3Click(TObject *Sender)
{
if(!pause3)
{
pause3 = true;
PauseBtn3->Caption = "Продолжить";
NameFile = PictureDir + AnsiString("\\coffee.jpg");
BankForm->Terminal3->Picture->LoadFromFile(NameFile.c_str());
}
else
{
pause3 = false;
PauseBtn3->Caption = "Пауза";
NameFile = PictureDir + AnsiString("\\money.jpg");
BankForm->Terminal3->Picture->LoadFromFile(NameFile.c_str());
}
}
//---------------------------------------------------------------------------
void __fastcall TBankForm::Timer1Timer(TObject *Sender)
{
if(n1 == 0)
{
n1 = 0;
if(in_queue==0)
{
NameFile = PictureDir + AnsiString("\\apparat.jpg");
BankForm->Terminal1->Picture->LoadFromFile(NameFile.c_str());
}
}
else
{
n1--;
Time1->Caption = n1;
}
if(n2 == 0)
{
n2 = 0;
if(in_queue==0)
{
NameFile = PictureDir + AnsiString("\\apparat.jpg");
BankForm->Terminal2->Picture->LoadFromFile(NameFile.c_str());
}
}
else
{
n2--;
Time2->Caption = n2;
}
if(n3 == 0)
{
n3 = 0;
if(in_queue==0)
{
NameFile = PictureDir + AnsiString("\\apparat.jpg");
BankForm->Terminal3->Picture->LoadFromFile(NameFile.c_str());
}
}
else
{
n3--;
Time3->Caption = n3;
}
}
//-----------------------------------------------------
Список литературы:
1. Программирование в C++ Builder. А.Я. Архангельский, Бином, Москва, 2003.- 1151 с.
2. Конспект лекций по курсу Операционные системы лектор Родников В.В. 2009г.
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.