카테고리 없음

[스크랩] CreateThread로 스레드 생성하기 멀티스레드

99iberty 2021. 6. 29. 10:14

https://blog.codingcat.kr/58

 

[단막 Windows API] CreateThread로 스레드 생성하기

단막 Windows API CreateThread로 스레드 생성하기 본 포스팅에서는 CreateThread 를 사용하여 스레드를 생성하는 간단한 예를 정리한다. 새 스레드에서 실행할 프로시저 형식 새 스레드에서 호출할 프로

blog.codingcat.kr

 

 

https://tt91.tistory.com/18

 

멀티쓰레드 연습(win32 api(CreateThread))

#include #include DWORD WINAPI threadFun1(void *lpVoid) { int b = 0; for (int i = 0; i < 15; i++) { std::cout << i << " - Fun1()" << std::endl; } return 0; } int main() { HANDLE hThread_1 = CreateTh..

tt91.tistory.com

 

#include <iostream>
#include <Windows.h>
#define THREAD_COUNT 2
DWORD WINAPI threadFun1(void *lpVoid)
{
 int b = 0;
 for (int i = 0; i < 15; i++)
 {
  std::cout << i <<" - Fun1()" << std::endl;
 }
 return 0;
}
DWORD WINAPI threadFun2(void *lpVoid)
{
 int b = 0;
 for (int i = 0; i < 15; i++)
 {
  std::cout << i <<" - Fun2()" << std::endl;
 }
 return 0;
}
int main()
{
 HANDLE hThread[THREAD_COUNT];
 hThread[0] = CreateThread(NULL, 0, ::threadFun1, NULL, 0, NULL);
 hThread[1] = CreateThread(NULL, 0, ::threadFun2, NULL, 0, NULL);
 for (int i = 0; i < 15; i++)
 {
  std::cout << i <<" - main()" << std::endl;
 }
 WaitForMultipleObjects(THREAD_COUNT, hThread,true, INFINITE);
 CloseHandle(hThread[0]);
 CloseHandle(hThread[1]);
 return 0;
}
출처: https://tt91.tistory.com/18 [티티의 게임 & 개발 블로그]