◆ 무한한 가능성/& Visual C/C++

Thread in MFC>

치로로 2009. 8. 20. 14:42
<<Thread in MFC>>



CObject
-CCmdTarget
--CWinThread



*CWinThread 클래스의 용도는 두가지로 구분
1. 작업자 스레드 : control, operate
2. 사용자 인터페이스 스레드 : input, output


* AfxBeginThread 함수 - 작업자 스레드
CWinThread *AfxBeginThread(
  AFX_THREADPROC pfnThreadProc,
  LPVOID pParam,
  int nPriority = THREAD_PRIORITY_NORMAL,
  UINT nStackSize = 0,
  DWORD dwCreateFlags = 0,
  LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);

//  AFX_THREADPROC pfnThreadProc, ......................>> 실행시킬 함수 포인터
//  LPVOID pParam, .................................................>> 함수에 전달할 포인터
//  int nPriority = THREAD_PRIORITY_NORMAL, ...........>> 스레드 우선 순위 등급
//  UINT nStackSize = 0, ...........................................>> 초기 스택 크기
//  DWORD dwCreateFlags = 0, .................................>> 생성 옵션
//  LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL ..>> 보안 속성


- SetThreadPriority(), GetThreadPriority() 함수가 스레드의 우선순위 등급을
변경하거나 얻기 위한 함수이다.


* AfxBeginThread 함수 - 사용자 인터페이스 스레드
CWinThread *AfxBeginThread(
  CRuntimeClass *pThreadClass,
  int nPriority = THREAD_PRIORITY_NORMAL,
  UINT nStackSize = 0,
  DWORD dwCreateFlags = 0,
  LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);

//  CRuntimeClass *pThreadClass,
.......>> CWinThread에서 파생된 런타임 클래스에 대한 포인터



*실행 순서
CWinThread 객체 생성 (CWinThread::CWinThread)
       ↓
스레드 루틴 실행 (CWinThread::CreateObject)
       ↓
스레드 우선 등급 설정 (CWinThread::SetthreadPriority)
       ↓
스레드 재개 (CWinthread::ResumeThread, 옵션에따라)


* AfxEndThread 함수
void AfxEndThread( UINT nExitCode );