2013년 4월 29일 월요일

[ C++ ]쓰레드 샘플 생성, 종료


쓰레드 생성 종료 간단 샘플

# include <iostream>
# include <boost/thread.hpp>
using namespace std;
using namespace boost;

/ / 인수없이 함수를 다중 스레드에서 실행
const int kCount = 1000;
const int kInterval = 100;

void PrintHello () {
   for (int i = 0; i! = kCount; + + i)
     if (! (i % kInterval)) cout << "Hello";
}
int main () {
   thread t_hello (& PrintHello); / / PrintHello 함수를 실행하는 스레드의 생성 및 실행

   t_hello.join (); / / t_hello가 실행하고있는 스레드 종료를 기다릴
   return 0;
}

댓글 없음:

댓글 쓰기