void IoServicePool::start(){ vector<boost::shared_ptr<boost::thread> > threadList; for(size_t i = 0; i < size_; ++i){ boost::shared_ptr<boost::thread> threadPtr(new boost::thread( boost::bind(&boost::asio::io_service::run, servicePool_[i]))); threadList.push_back(threadPtr); } for(size_t i = 0; i < threadList.size(); ++i){ threadList[i]->join(); } }
bool TePDISAMClassifier::RunImplementation() { // Extracting parameters TePDITypes::TePDIRasterPtrType input_raster; params_.GetParameter("input_raster", input_raster); std::vector< unsigned int > bands; params_.GetParameter("bands", bands); TePDITypes::TePDIRasterPtrType output_raster; params_.GetParameter("output_raster", output_raster); SpectralSamplesVecPtrT spectral_samples; params_.GetParameter("spectral_samples", spectral_samples); // Calc samples means std::vector< ClassReferenceData > refDataVector; TEAGN_TRUE_OR_RETURN( calcClassRefData( *spectral_samples, refDataVector ), "Internal error" ); // Init the output image TeRasterParams outputImgParams = output_raster->params(); outputImgParams.nBands( 1 ); outputImgParams.setDataType( TeUNSIGNEDLONG, -1 ); outputImgParams.projection( input_raster->params().projection() ); outputImgParams.boundingBoxLinesColumns( input_raster->params().boundingBox().x1(), input_raster->params().boundingBox().y1(), input_raster->params().boundingBox().x2(), input_raster->params().boundingBox().y2(), input_raster->params().nlines_, input_raster->params().ncols_ ); TEAGN_TRUE_OR_RETURN( output_raster->init( outputImgParams ), "Output raster init error" ); // Starting segmentation threads TeMutex inMutex; TeMutex& outMutex = inMutex; volatile bool abortFlag = false; const unsigned int maxSegThreads = TeGetPhysProcNumber(); std::vector< bool > linesProcStatusVec; linesProcStatusVec.resize( input_raster->params().nlines_, 0 ); if( params_.CheckParameter< int >( "enable_multi_thread" ) && ( maxSegThreads > 1 ) ) { std::vector< TeSharedPtr< SegThread > > threadsVec; unsigned int threadIdx = 0; for( threadIdx = 0 ; threadIdx < maxSegThreads ; ++threadIdx ) { TeSharedPtr< SegThread > threadPtr( new SegThread( progress_enabled_, *input_raster, bands, refDataVector, inMutex, outMutex, linesProcStatusVec, abortFlag, *output_raster ) ); threadPtr->start(); threadsVec.push_back( threadPtr ); } // Wait all threads to finish bool returnValue = true; for( threadIdx = 0 ; threadIdx < maxSegThreads ; ++threadIdx ) { threadsVec[ threadIdx ]->waitToFinish(); returnValue &= threadsVec[ threadIdx ]->getReturnValue(); } return returnValue; } else { SegThread threadInstance( progress_enabled_, *input_raster, bands, refDataVector, inMutex, outMutex, linesProcStatusVec, abortFlag, *output_raster ); threadInstance.run(); return threadInstance.getReturnValue(); } }
void Thread::run() { _thread = threadPtr(new boost::thread(boost::bind(&boost::asio::io_service::run, _ioService))); }