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

카일릭스 Q&A
[203] [질문]_beginthread 사용법
공일효 [kong15] 3354 읽음    2003-01-20 20:25
안녕하세요

kylix3에서 thread object를 사용하지 않고
_beginthread 함수를 써서 thread를 돌릴려고 했는데
잘 되지가 않네요.
application 하나 열어서 붙여넣었습니다.
하나의 thread만 돌리면 별 문제가 없는데 여러개를 돌리게되면
thread가 죽을때 꼭 sigsegv(11) message가 뜨네요.
그리고 loop안에 edit에 글을쓴다든지 로드를 좀 걸면 돌아가는 과정에서도
가끔 sigsegv(11) message가 뜨면서 죽을때가 있네요.
혹시 beginthread 말고 다른 방법이 없나요??

내공이 부족해 도데체가 뭘 잘못하고있는건지 몰르겠네요..쩝..
나는 언제나 이런데서 답변글 적을수 있을려나...ㅠ.ㅠ
조언좀 부탁드리겠습니다.

아래에 코드 붙입니다.
참!! 글구 builder6에 붙여봤는데 아무 문제 없이 잘 되었습니다.

==============================================================================
//---------------------------------------------------------------------------

#include <clx.h>
#pragma hdrstop

#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.xfm"

void test_thread1( void *pParam  );
void test_thread2( void *pParam  );
void test_thread3( void *pParam  );
void test_thread4( void *pParam  );
void test_thread5( void *pParam  );
void start_thread(void);
void end_thread(void);

TForm1 *Form1;
int thread_id1,thread_id2,thread_id3,thread_id4,thread_id5;
int isRunning1,isRunning2,isRunning3,isRunning4,isRunning5;
int state1,state2,state3,state4,state5;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    isRunning1 = isRunning2 = isRunning3 = isRunning4 = isRunning5 = 0;
    state1 = state2 = state3 = state4 = state5 = 1;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BtnStartClick(TObject *Sender)
{
    Form1->Memo1->Lines->Add("on");
    start_thread();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BtnEndClick(TObject *Sender)
{
    Form1->Memo1->Lines->Add("off");
    end_thread();
}
//---------------------------------------------------------------------------



void start_thread(void)
{
    state1 = state2 = state3 = state4 = state5 = 1;
    if( (thread_id1 = _beginthread(test_thread1,NULL,NULL)) == -1)
    {
        Form1->Memo1->Lines->Add("error");
        return;
    }

    if( (thread_id2 = _beginthread(test_thread2,NULL,NULL)) == -1)
    {
        Form1->Memo1->Lines->Add("error");
        return;
    }

    if( (thread_id3 = _beginthread(test_thread3,NULL,NULL)) == -1)
    {
        Form1->Memo1->Lines->Add("error");
        return;
    }

    if( (thread_id4 = _beginthread(test_thread4,NULL,NULL)) == -1)
    {
        Form1->Memo1->Lines->Add("error");
        return;
    }
    if( (thread_id5 = _beginthread(test_thread5,NULL,NULL)) == -1)
    {
        Form1->Memo1->Lines->Add("error");
        return;
    }

}

void end_thread(void)
{
    state1 = state2 = state3 = state4 = state5 = 0;

    while(isRunning1)
    {
        Sleep(1);
    }
    while(isRunning2)
    {
        Sleep(1);
    }
    while(isRunning3)
    {
        Sleep(1);
    }
    while(isRunning4)
    {
        Sleep(1);
    }
    while(isRunning5)
    {
        Sleep(1);
    }



}
void test_thread1(void *pParam)
{
    isRunning1 = 1;
    while(state1)
    {

        Sleep(10);
    }
    isRunning1 = 0;
}

void test_thread2(void *pParam)
{
    isRunning2 = 1;
    while(state2)
    {

        Sleep(10);
    }
    isRunning2 = 0;

}
void test_thread3(void *pParam)
{
    isRunning3 = 1;
    while(state3)
    {

        Sleep(10);
    }
    isRunning3 = 0;

}
void test_thread4( void *pParam )
{
    isRunning4 = 1;
    while(state4)
    {

        Sleep(10);
    }
    isRunning4 = 0;

}
void test_thread5( void *pParam  )
{
    isRunning5 = 1;
    while(state5)
    {

        Sleep(10);
    }
    isRunning5 = 0;

}





void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    Form1->StatusBar1->Panels->Items[0]->Text = IntToStr(isRunning1);
    Form1->StatusBar1->Panels->Items[1]->Text = IntToStr(isRunning2);
    Form1->StatusBar1->Panels->Items[2]->Text = IntToStr(isRunning3);
    Form1->StatusBar1->Panels->Items[3]->Text = IntToStr(isRunning4);
    Form1->StatusBar1->Panels->Items[4]->Text = IntToStr(isRunning5);
===========================================================================

+ -

관련 글 리스트
203 [질문]_beginthread 사용법 공일효 3354 2003/01/20
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.