|
#include <vcl.h>
#pragma hdrstop
#include "thread5main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
int Count;
HANDLE hCountUp, hCountDown; //요기요??
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
mMessage->Lines->Clear();
Count = 0;
hCountUp = CreateEvent(NULL, FALSE, TRUE, NULL); //요기요??
hCountDown = CreateEvent(NULL, FALSE, FALSE, NULL); //요기요??
UpThread = new TCounterThread(TRUE);
DownThread = new TCounterThread(FALSE);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
UpThread->Terminate();
DownThread->Terminate();
CloseHandle(hCountUp);
CloseHandle(hCountDown);
}
//---------------------------------------------------------------------------
__fastcall TCounterThread::TCounterThread(bool TheCountUp) : TThread(TRUE)
{
FreeOnTerminate = TRUE;
CountUp = TheCountUp;
Resume();
}
void __fastcall TCounterThread::Execute(void)
{
while(!Terminated)
{
if(CountUp)
WaitForSingleObject(hCountUp, INFINITE); //요기요??
else
WaitForSingleObject(hCountDown, INFINITE); //요기요??
if(CountUp)
{
Count +=10;
Sleep(1000);
Synchronize(UpdateDisplay);
SetEvent(hCountDown); //요기요??
}
else
{
Count -=10;
Sleep(1000);
Synchronize(UpdateDisplay);
SetEvent(hCountUp); //요기요??
}
}
}
void __fastcall TCounterThread::UpdateDisplay(void)
{
if(Form1->mMessage->Lines->Count > 200)
Form1->mMessage->Lines->Clear();
if(CountUp)
Form1->mMessage->Lines->Add("Count up thread "+ IntToStr(Count));
else
Form1->mMessage->Lines->Add("Count down thread "+ IntToStr(Count));
}
중간중간에 보면요 //요기요?? 라는 부분에 대해서 자세히 설명좀 해주세요
너무 어려워요 벌써 책 5번째 똑같은걸 읽고있습니다. 번역본이라 말이 매끄럽지 못해서
먼말인지... 도통...몰겟어여 고수님들 지도 부탁드려요
헤더파일도 원하시면 올려드릴게요
|