C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[24079] Re:쓰레드 질문입니다 . 버그를 못찾겠어요.
임문환 [mhlim] 855 읽음    2003-02-05 17:36
일단 Execute 내부 코드와 프로그램 전체를 볼 때 Terminated가 true가 되는 경우는 프로그램이 종료되는 시점 밖에 없습니다.
따라서 무한 루프를 돌면서 게이지 위치를 증가시키고 있네요.
Thread는 내부에 종료 조건을 주어서 스스로 종료되게 하든지 아니면 외부에서 강제로 종료시키든지 해야 합니다.
지금 이 상태가 반드시 프로그램을 다운시킨다고는 할 수 없지만 CPU 클럭을 많이 사용하게 된다는 것은 분명합니다.
그리고, Thread의 Priority가 높을수록 다른 스레드의 실행을 지연시킬 가능성이 높아집니다.


머리돌 님이 쓰신 글 :
: [C++ Builder 4 Programming Bible]책에 있는 Thread 내용그대로 작성한것입니다.
:
: 5.0버전을 사용중인데.
: 책의 내용을 그대로 입력해서 3회이상 실행시 컴이 멈춰버립니다.
: 예제로 나온 3가지 모두 해 봤는데 상태는 모두 같구요. 어디에 버그가 있는지 알려 주세요.
:
:
: //Header부
: --------------------------------------------------------------------------------------
: //---------------------------------------------------------------------------
:
: #ifndef SyncUnitH
: #define SyncUnitH
: //---------------------------------------------------------------------------
: #include <Classes.hpp>
: #include <Controls.hpp>
: #include <StdCtrls.hpp>
: #include <Forms.hpp>
: #include "CGAUGES.h"
: //---------------------------------------------------------------------------
: class TScreenThread : public TThread
: {
:   private:
:     int GaugeNum;
:     void __fastcall Execute(void);
:     void __fastcall UpdateThread(void);
:   public:
:     __fastcall TScreenThread(int TheNum);
: };
: //---------------------------------------------------------------------------
: class TForm1 : public TForm
: {
: __published:    // IDE-managed Components
:   TCGauge *CGauge1;
:   TCGauge *CGauge2;
:   TCGauge *CGauge3;
:   TButton *Button1;
:   void __fastcall Button1Click(TObject *Sender);
: private:    // User declarations
: public:        // User declarations
:   __fastcall TForm1(TComponent* Owner);
: };
: //---------------------------------------------------------------------------
: extern PACKAGE TForm1 *Form1;
: //---------------------------------------------------------------------------
: #endif
:
:
: //Source 부
: --------------------------------------------------------------------------------------
: //---------------------------------------------------------------------------
:
: #include <vcl.h>
: #pragma hdrstop
:
: #include "SyncUnit.h"
: //---------------------------------------------------------------------------
: #pragma package(smart_init)
: #pragma link "CGAUGES"
: #pragma resource "*.dfm"
: TForm1 *Form1;
: //---------------------------------------------------------------------------
: __fastcall TForm1::TForm1(TComponent* Owner)
:   : TForm(Owner)
: {
: }
: //---------------------------------------------------------------------------
: __fastcall TScreenThread::TScreenThread(int TheNum):TThread(true)
: {
:   FreeOnTerminate = true;
:   GaugeNum=TheNum;
:   Resume();
: }
: //---------------------------------------------------------------------------
: void __fastcall TScreenThread::Execute(void)
: {
:   while(!Terminated)
:   {
:     Form1->CGauge1->Progress=0;
:     Form1->CGauge2->Progress=0;
:     Form1->CGauge3->Progress=0;
:     for(int x=0;x<100;x++)
:       Synchronize(UpdateThread);
:   }
: }
: //---------------------------------------------------------------------------
: void __fastcall TScreenThread::UpdateThread(void)
: {
:   switch(GaugeNum){
:     case 0: Form1->CGauge1->Progress++; break;
:     case 1: Form1->CGauge2->Progress++; break;
:     case 2: Form1->CGauge3->Progress++; break;
:   }
: }
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
:   TScreenThread *T;
:   for(int i=0;i<3;i++)
:     T=new TScreenThread(i);
: }
: //---------------------------------------------------------------------------
:
:

+ -

관련 글 리스트
24059 쓰레드 질문입니다 . 버그를 못찾겠어요. 머리돌 696 2003/02/05
24079     Re:쓰레드 질문입니다 . 버그를 못찾겠어요. 임문환 855 2003/02/05
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.