void ThreadPool::start() { if (started) return; for (int i=0; i<threadCount; ++i) { TaskThread* thread = new TaskThread(); threads << thread; thread->start(); } started = true; }
NPT_Result TaskGroup::startNewThread(Task *task) { TaskThread *thread = new TaskThread(this); WriteLocker locker(m_threadListLock); m_threadList.Add(thread); NPT_Result nr = thread->start(task); if (NPT_FAILED(nr)) { m_threadList.Remove(thread); delete thread; delete task; } return nr; }
void ThreadPool::start() { if (m_started) { return; } for (int i = 0;i<m_threadCount;++i) { TaskThread * thread = new TaskThread(); m_threads << thread; thread->start(); } m_started = true; }
void TaskService::adjustThreadCount() { OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_threadMutex); removeFinishedThreads(); int numActiveThreads = 0; for( TaskThreads::iterator i = _threads.begin(); i != _threads.end(); i++ ) { if (!(*i)->getDone()) numActiveThreads++; } int diff = _numThreads - numActiveThreads; if (diff > 0) { OE_DEBUG << LC << "Adding " << diff << " threads to TaskService " << std::endl; //We need to add some threads for (int i = 0; i < diff; ++i) { TaskThread* thread = new TaskThread( _queue.get() ); _threads.push_back( thread ); thread->start(); } } else if (diff < 0) { diff = osg::absolute( diff ); OE_DEBUG << LC << "Removing " << diff << " threads from TaskService " << std::endl; int numRemoved = 0; //We need to remove some threads for( TaskThreads::iterator i = _threads.begin(); i != _threads.end(); i++ ) { if (!(*i)->getDone()) { (*i)->setDone( true ); numRemoved++; if (numRemoved == diff) break; } } } OE_INFO << LC << "TaskService [" << _name << "] using " << _numThreads << " threads" << std::endl; }