본문 바로가기

쓰기

음 일단 쓰레드를 사용하는 파일은
CAutoLoad 클래스 하나뿐이구요.

CustomDic에 포함됩니다.




5초마다 한번씩 파일리스트에 등록된 파일의 수정된 날짜를 체크해서
새로 갱신된것이면 새로 읽는다...라는 기능을 가지고 있는데,



애초부터 쓰레드가 동작조차 하지 않습니다.
어떻게 해야할까요;

 #pragma once
#include "tstring.h"
#include <vector>
#include <map>

using namespace std;

struct DicWord
{
    int WordN;
    int WordLen;
};

class CAutoLoad
{
public:
    CAutoLoad(void);
public:
    ~CAutoLoad(void);

public:
    void AddDic(LPCWSTR CustomPath);

    map<int,int> GetKeyIndex();
    vector<map<UINT,DicWord>> GetKeyBook();
    vector<string> GetValueList();
    int GetWordN();
    int GetBookN();

    bool GetChanged();
    void SetChanged();

    void FileClear();


    //Load 쓰레드 처리
    bool m_bChanged;
    CWinThread * m_pLoadThread;
    void Callback();
    static UINT CallbackStub(LPVOID param);

private:
    void ResetDic();
    void ReadDic(LPCWSTR CustomPath);

    void SetKey(LPCSTR JpnWord,LPCSTR KorWord);

    //사전 데이터
    map<int, int> KeyIndex;
    vector<map<UINT,DicWord>> KeyBook;

    vector<string> ValueList;

    int WordN;
    int BookN;

    vector<wstring> FileList;
    vector<DWORD> FileWriteTime;
};

 #include "StdAfx.h"
#include "AutoLoad.h"
#include "SubFunc.h"
#include "hash.hpp"

volatile bool m_bRunning;
CCriticalSection g_cs;

CAutoLoad::CAutoLoad(void)
{
    m_bRunning=true;
    m_pLoadThread = AfxBeginThread(CAutoLoad::CallbackStub,this);
}

CAutoLoad::~CAutoLoad(void)
{
    g_cs.Lock();
    m_bRunning=false;
    g_cs.Unlock();
    if(NULL != m_pLoadThread)
    {
        ::WaitForSingleObject(m_pLoadThread->m_hThread,INFINITE);
        delete m_pLoadThread;
        m_pLoadThread = NULL;
    }
}

void CAutoLoad::FileClear()
{
    g_cs.Lock();
    FileList.clear();
    FileWriteTime.clear();
    g_cs.Unlock();
}

UINT CAutoLoad::CallbackStub(LPVOID param)
{
    while(1)
    {
        Sleep(5000);
        g_cs.Lock();
        if(!m_bRunning)
        {
            g_cs.Unlock();
            break;
        }
        else
        {
            g_cs.Unlock();
            static_cast<CAutoLoad*>(param)->Callback();  // 여기서 멤버 함수를 호출해주죠.
        }
    }
    return 0L;
}

void CAutoLoad::Callback()
{

    //파일체크 개시
    g_cs.Lock();
    int FileN=(int)FileList.size(); //Size값이 실시간으로 변하지 않도록
    g_cs.Unlock();

    bool bReload=false;
    HANDLE h_file=NULL;
    for(int i=0;i<FileN;i++)
    {
        h_file=CreateFile(FileList[i].c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
                                                                             OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

        if(h_file != INVALID_HANDLE_VALUE){
            FILETIME create_time, access_time, write_time;

            // 지정된 파일에서 파일의 생성, 최근 사용 그리고 최근 갱신된 시간을 얻는다.
            GetFileTime(h_file, &create_time, &access_time, &write_time);
            CloseHandle(h_file);

            g_cs.Lock();
            if(write_time.dwLowDateTime>FileWriteTime[i])
            {
                FileWriteTime[i]=write_time.dwLowDateTime;
                bReload=true;
            }
            g_cs.Unlock();
        }
    }
    

    if(bReload)
    {
        ResetDic();
        g_cs.Lock();
        for(int i=0;i<FileN;i++)
        {
            ReadDic(FileList[i].c_str());
        }
        m_bChanged=true;
        g_cs.Unlock();
    }
}

void CAutoLoad::AddDic(LPCWSTR Path)
{
    g_cs.Lock();
    FileList.push_back(Path);
    FileWriteTime.push_back(0);
    g_cs.Unlock();
}

void CAutoLoad::ReadDic(LPCWSTR Path){ /* 파일 읽기 작업*/ }
void CAutoLoad::ResetDic(){ /*초기화 작업*/}
void CAutoLoad::SetKey(LPCSTR JpnWord, LPCSTR KorWord){    /*단어 추가 작업*/ }

//이하는 모두 g_cs.Lock(); 데이터빼내고 g_cs.Unlock(); return 데이터
map<int,int> CAutoLoad::GetKeyIndex(){...}
vector<map<UINT,DicWord>> CAutoLoad::GetKeyBook(){...}
vector<string> CAutoLoad::GetValueList(){...}
int CAutoLoad::GetBookN(){...}
int CAutoLoad::GetWordN(){...}
bool CAutoLoad::GetChanged(){...}
void CAutoLoad::SetChanged(){...}


분류 :
Talk
조회 수 :
10808
등록일 :
2008.12.25
20:42:46
엮인글 :
https://arallab.hided.net/4117/cc1/trackback
게시글 주소 :
https://arallab.hided.net/board_devtalk/4117

whoami

2008.12.26
21:27:55
음. 눈에 바로 띄는 것은 특별히 없군요.. 실제로 돌려보지 않으면;;

어쨌든.. 확인하셔야 할 사항은..
1. CAutoLoad 가 제대로 생성되었는가?
2. 생성 후 쓰레드가 제대로 만들어졌는가? (m_pLoadThread 에 제대로 된 CWinThread 주소가 들어갔는가?)
3. 쓰레드가 혹시 한번 돌고 그대로 종료되지 않았는가?

인 것 같군요. 각각 디버그 메세지를 띄우거나 디버거를 넣어 확인해 보세요.

Hide_D

2008.12.26
22:53:45
확인 결과
m_pLoadThread = AfxBeginThread(CAutoLoad::CallbackStub,this);
에서 F10 누르는 순간 정지.

CallBackStub의
while(1)에 브포를 걸어두고 있었는데 여기로 넘어오질 않네요.
List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 Talk [필독] 테스트필터 사용시 주의사항 라파에 2008-08-03 155436
209 Talk 음 제가 컴퓨터를 못하는 사람이라 뻘글일 수도 있겠지만.. [2] 쥬빌 2008-12-30 14389
208 Talk 히데님이 말씀하신 테스트파일 [2] file 유르_리샤 2008-12-29 11530
207 Talk Fixline용 텍스트 파일.... [3] file 처음처럼만 2008-12-29 11753
206 Talk 필터에 MFC로 모달리스 창을 띄웠을때=ㅅ=; [4] file Hide_D 2008-12-27 13934
205 Talk FixLine 23일자 파일은 무시설정에 문제가 있는듯하네요 [7] 류제로 2008-12-26 15841
» Talk 쓰레드를 사용하려고 하는데 제대로 안되네요; [2] Hide_D 2008-12-25 10808
203 Talk 기리기리 [] 함수 내부 처리 [1] Hide_D 2008-12-23 12463
202 Archive [플러그인,소스] FixLine RC2 081223 [4] file Hide_D 2008-12-23 17424
201 Talk 아아아아앍 cmd /u !!!!!!!!!!!!!!!!!! [1] Hide_D 2008-12-22 12323
200 Archive [플러그인,소스] FixLine RC 081222 file Hide_D 2008-12-22 12576
199 Archive [플러그인,소스] FixLine 테스트버전 081221 [5] file Hide_D 2008-12-21 15475
198 Archive [플러그인,소스] FixLine 테스트버전 081220_2 [2] file Hide_D 2008-12-20 13376
197 Talk ezTransXP 플러그인 버그 =ㅅ=?? [2] Hide_D 2008-12-20 12427
196 Archive [플러그인,소스] FixLine 테스트버전 081219 file Hide_D 2008-12-19 11449
195 Talk [오류보고]ATcode 버퍼크기 무시 버그 [1] file HaruKaze 2008-12-18 12813
194 Archive [플러그인,소스] FixLine 테스트버전 081217 file Hide_D 2008-12-17 12415
193 OtherFiles fixline 테스트 3차 [2] file 처음처럼만 2008-12-16 16074
192 Talk FixLine 테스트버전 081215 [1] file 그레이 2008-12-16 20429
191 OtherFiles fixline 테스트 2차 file 처음처럼만 2008-12-16 13341
190 OtherFiles fixline 테스트 [1] file 처음처럼만 2008-12-16 15297