소프트웨어

thread fool에 대해서 알아보자.

개발자_이훈규 2014. 2. 28. 17:27

1. 키워드

thread,fool,스레드,풀,pthread


2.

우선 wikipedia를 보자.

http://en.wikipedia.org/wiki/Thread_pool_pattern



3.

wiki의 내용에 기초해서 보자면

이 thread pool patern을 적용할 때는 thread-safety가 확보되어 있어야 한다.

자바의 경우엔 synchronized라는 키워드를 사용해서 보호한다.



4.

간단한 예제가 있다.

http://software.intel.com/sites/products/documentation/studio/composer/en-acus/2011Update/compiler_c/optaps/common/optaps_par_multicore_thrdpool.htm

여기선 예제로 초기화 하는 부분만 예를 들어주엇다.


 // Initialization method/function

{
  DWORD tid;
  // Create initial pool of threads
   for (int i = 0; i < MIN_THREADS; i++)
   {
    HANDLE *ThHandle = CreateThread (NULL,0,CheckPoolQueue,NULL,0,&tid);
    if (ThHandle == NULL)
    // Handle Error
    else
    RegisterPoolThread (ThHandle);
   }
}



5.

이젠 예제를 찾아보았다.

http://exceptional-code.blogspot.kr/2013/05/a-c-thread-pool-implementation-using.html

여기 블로그에서 github에 소스를 다운 받은 후 소스 분석을 해보았다.

( 요즘에 코드 컨벤션이나 가독성에 대해서 고민하고 있는데 이 소스는 주석은 친절하지만 엔터가 많이 없어서 보긴 어렵다.)


point)

① mutex의 is_locked를 운용하는 것, 처음본다. 좋다

② 소스에 있는 vector는 라이센스가 걸려있는 것이므로 상업적으로 이용할 경우에 심각한 문제를 발생 할 수 있다.


License


This vector class library has a dual license system. You can use it for free in open

source software, or pay for using it in proprietary software.

You are free to copy, use, redistribute and modify this software under the terms of

the GNU General Public License as published by the Free Software Foundation, 

version 3 or any later version. See the file license.txt.

Commercial licenses are available on request. 


사용법 코드 : http://cafe.naver.com/raic/18


③ pthread에 새로운 함수 2가지, pthread_self, pthread_exit

쓰던것만 써서 그런지 이런 좋은걸 한번도 써보지 않았다.



6.

http://www.codeproject.com/Questions/580332/exampleplusofplusthreadpoolplusinplusc-2fc-2b-2b