1515 You should have received a copy of the GNU General Public License
1616 along with this program. If not, see <http://www.gnu.org/licenses/>.
1717*/
18-
18+ # include < algorithm >
1919#include < stdlib.h>
2020#include " threadpool.h"
2121
@@ -26,7 +26,8 @@ pthread_mutex_t ThreadPool::_mutex_work_completion = PTHREAD_MUTEX_INITIALIZER;
2626
2727
2828ThreadPool::ThreadPool (unsigned int num_thread)
29- :_num_thread(num_thread)
29+ :_thread_pool(num_thread)
30+ ,_num_thread(num_thread)
3031,_worker_queue(num_thread, NULL )
3132,_queue_size(num_thread)
3233{
@@ -37,17 +38,10 @@ ThreadPool::ThreadPool(unsigned int num_thread)
3738 sem_init (&_available_work, 0 , 0 );
3839 sem_init (&_available_thread, 0 , _queue_size);
3940 pthread_mutex_unlock (&_mutex_sync);
40- }
4141
42- void ThreadPool::initialize_thread ()
43- {
44- for (unsigned int i = 0 ; i < _num_thread; ++i)
45- {
46- pthread_t tempThread;
47- pthread_create (&tempThread, NULL , &ThreadPool::thread_execute, (void *) this );
48- // threadIdVec[i] = tempThread;
42+ for (std::vector<pthread_t >::iterator i = _thread_pool.begin (); i != _thread_pool.end (); ++i) {
43+ pthread_create (&*i, NULL , &ThreadPool::thread_execute, this );
4944 }
50-
5145}
5246
5347ThreadPool::~ThreadPool ()
0 commit comments