18 #include <boost/thread.hpp> 70 std::vector<BSHP<ThreadLoop>>
Threads()
override;
119 ThreadMgr::~ThreadMgr()
128 std::vector<BSHP<ThreadLoop>> threads;
143 m_nThread = boost::thread::hardware_concurrency() - 1;
166 BSHP<ThreadLoop> ptr =
m_threader->CreateForNewThread();
183 m_prog->ProgressStatus(p);
186 int sum, cnt, cntBase;
191 for (
size_t i = 0; i <
m_counts.size(); ++i)
193 while (sum >= cnt && p < 1)
197 m_prog->ProgressStatus(p);
200 boost::this_thread::sleep(boost::posix_time::millisec(100));
210 for (
size_t i = 0; i <
m_vThreads.size(); ++i)
void FinishThreads()
When all iterations are complete this terminates the threads.
std::vector< int > VecInt
std::vector< myThread > m_vMyThread
vector of created threads
void MonitorThreads()
Monitors the progress of all the threads.
Implmentation of ThreadMgr.
void SetThreadLoopClass(BSHP< ThreadLoop > a_) override
std::vector< BSHP< ThreadLoop > > Threads() override
Gets the threads managed by this class.
ThreadMgrImpl()
Constructor.
BSHP< Observer > m_prog
observes the threads and gives feedback of % complete
int m_nIter
total number of iterations for all threads combined
BSHP< ThreadLoop > m_threader
the worker class that is duplicated to run in multiple threads
void ExplicitlySetNumThreads(int a_nThreads) override
Manages a multi-threaded process.
static BSHP< ThreadMgr > New()
Creates a ThreadMgr.
void RunThreads(int a_nIter) override
Executes the threads.
convenience struct for threads
int m_nThread
number of threads running
VecInt m_beg
starting index for each thread
std::vector< boost::thread > m_vThreads
actual boost threads that are run
VecInt m_thrdNumIter
number of iterations for each thread
myThread(BSHP< ThreadLoop > a_)
Constructor.
VecInt m_counts
number of completed iterations for each thread
void operator()()
worker code that is executed
BSHP< ThreadLoop > m_
Worker thread.
void SetupThreads()
Sets up the threads.
void SetObserver(BSHP< Observer > a_prog) override