분류 전체보기 372

Thread in C++> example code. - Thread05

Thread in C++> example code. - Thread05 //------------------------------------------------------------------------------ // C++의 Class를 이용한 스레드 예제 - 시작 //------------------------------------------------------------------------------ #include #include #include #include #include #define ONEK 1024 typedef struct _SumInfo { int a, b, s; }SUMINFO, *PSUMINFO; void WriteString(const char* lpszFormat, ...

Thread - C 런타임 함수와 WIN32 API

내 용 WIN32 API C 런타임 함수 문자열 형식 지정 wsprintf, vwsprintf sprintf, vsprintf 문자열 출력 WriteFile(h_ConsoleOut, ...) printf, vprintf 스레드 생성 CreateThread _beginthread, _beginthreadex 스레드 종료 return, ExitThread _endthread, _endthreadex 힙 메모리 할당 HeapAlloc malloc(new) 힙 메모리 해제 HeapFree free(delete) 스레드 함수 원형 DWORD WINAPI ThreadProc( LPVOID lpParameter); void(__cdecl *start_address)(void *), void(__stdcall *sta..

Thread in C runtime library> example code. - Thread04

Thread in C runtime library> example code. - Thread04 //------------------------------------------------------------------------------ // C Runtime Library를 이용한 스레드 예제 - 시작 //------------------------------------------------------------------------------ #include #include #include #include #define ONEK 1024 typedef struct _SumInfo { int a, b, s; }SUMINFO, *PSUMINFO; // a 에서 b까지의 합을 s에 저장 unsigned..

Thread in C runtime library (다중스레드, Multi-Thread)

▷ _tiddata : 다중 스레드에서의 C runtime library 문제점을 해소하려면, 이와 같은 전역변수, 정적변수들을 스레드당 별도로 생성하여 관리해야 한다. 이러한 데이터들을 모아놓은 것이 구조체 _tiddata 이다. ▶ 다중 스레드(/MT) - LIBCMT.LIB ▶ 다중 스레드 디버그(/MTd) - LIBCMTD.LIB ▶ 다중 스레드 DLL(/MD) - MSVCRt.LIB ▶ 다중 스레드(/MDd) - MSVCRtD.LIB *스레드 생성 ** _beginthread unsigned long _beginthread( void(__cdecl * start_address)(void*), unsigned stack_size, void *arglist ); // start_address : 생..

[함수호출규약] __cdecl, __stdcall, __fastcall, __thiscall

■ 함수 호출 규약 종류 → __cdecl → __stdcall → __fastcall → __thiscall ■ __cdecl(C declaration) □ 인자 전달 : 오른쪽 → 왼쪽 □ 스택 정리 : 호출한 측에서 인자를 스택에서 꺼냄 ■ __stdcall(Standard call) □ 인자 전달 : 오른쪽 → 왼쪽 □ 스택 정리 : 호출 당한 측에서 스택에서 인자를 꺼냄 ■ __fastcall □ 인자 전달 : 처음 두개의 DWORD 또는 그보다 작은 크기의 인자는 ECX와 EDX 레지스터로 전달, 나머지는 오른쪽 → 왼쪽 □ 스택 정리 : 호출 당한 측에서 스택에서 인자를 꺼냄 ■ __thiscall □ 인자 전달 : 오른쪽 → 왼쪽 □ 스택 정리 : 호출 당한 측에서 스택에서 인자를 꺼냄 □..

Thread example code. - Thread03

Thread example code. - Thread03 //------------------------------------------------------------------------------ // WIN32 API를 이용한 스레드 예제 - 시작 //------------------------------------------------------------------------------ #include #define ONEK 1024 typedef struct _SumInfo { int a, b, s; }SUMINFO, *PSUMINFO; // a 에서 b까지의 합을 s에 저장 DWORD WINAPI Sum(void* p); // 스레드 함수 HANDLE g_hConsoleOut; // 콘솔 ..

Thread

*스레드 생성 : 스레드 생성시.. 프로세스에 'CPU에 레지스터'와 '메모리 영역에 static영역'이 추가된다. ※ 프로세스의 구성요소는... CPU에 레지스터, 메모리 영역에 code영역, 커널오브젝트, Heap영역, static영역으로 구성된다. ** CreateThread API 함수 HANDLE CreateThread( LPSECURITY_ATTRIBUTES lpThreadAttributes, // 커널 오브젝트에 대한 보안 속성 DWORD dwStackSize, // 스레드가 사용할 스택 영역의 크기 LPTHREAD_START_ROUTINE lpStartAddress, // 스레드 오브젝트가 실행할 시작점 LPVOID lpParameter, // 생성될 스레드에게 전달할 포인터 DWORD d..

Kernel Object

- Event : 시그널과 넌시그널 상태를 갖는 커널 오브젝트, 이벤트가 발생하였을 때 하나 또는 여러 개의 스레드에게 알려 줄 수 있다. - Mutex : 열쇠와 같은 개념으로 특정 시점에서 단 하나의 스레드만이 소유할 수 있다. 공유 자원을 사용해야 하는 부분에서는 뮤텍스를 소유하다가 사용이 끝나면 놓아주면 된다. (뮤텍스=1개의화장실키, 스레드=사람이라면... 1개의 화장실에 1사람이 1개의열쇠를 들고 들어가서 잠그고 다른사람들은 대기) - Semaphore : 뮤텍스가 단 하나의 스레드만 소유하는 것과 달리 여러 개의 스레드를 소유할 수 있다. - Waitable Timer : 특정 시간이 되면 스레드에게 통보한다. - Change Notification : 디렉토리에 관하여 개발자가 선택한 특정..