31using std::ostream, std::map, std::cout, std::endl;
33const size_t g_sleeptime = 10000000;
34const size_t g_multTasks = 8;
37enum EProc {
start, clean};
41 bool runTask(EProc ) {
46 unsigned long threadID()
const {
53ostream &operator<< (ostream &_stream,
const TTestTask &_task)
55 _stream << _task.threadID();
60void stressThreadPool(
size_t _numThreads = 4,
bool _needDbg =
false)
62 size_t numTasks(_numThreads * g_multTasks);
64 vector <TTestTask> tasksList(numTasks);
67 for (
size_t j = 0; j < 4; ++j )
69 cout <<
"+++++++++ Starting iteration #" << j <<
" ++++++++++++"<< endl;
70 for (
size_t i = 0; i < numTasks; ++i) {
71 threadPool.PushTask(tasksList[i], start);
74 cout <<
"\n ****** Drain the tasks queue ******" << endl;
77 cout <<
"\n Stopping..." << endl;
78 threadPool.Stop(
true);
84 typedef map<unsigned long, size_t> counter_t;
87 vector <TTestTask>::const_iterator iter = tasksList.begin();
88 vector <TTestTask>::const_iterator iter_end = tasksList.end();
89 for (; iter != iter_end; ++iter) {
90 counter_t::iterator found = counter.find(iter->threadID());
91 if (found == counter.end())
92 counter.insert(counter_t::value_type(iter->threadID(), 1));
94 found->second = found->second + 1;
99 cout <<
"\n************* RESULT ****************" << endl;
101 counter_t::const_iterator iter = counter.begin();
102 counter_t::const_iterator iter_end = counter.end();
104 for (; iter != iter_end; ++iter) {
105 cout <<
"Thread " << iter->first <<
" was used " << iter->second <<
" times\n";
108 if (iter->second != g_multTasks)
112 cout <<
"ThreadPool: the simple test status: " << (testOK ?
"OK" :
"Failed") << endl;
static Int_t Sleep(ULong_t secs, ULong_t nanos=0)
Static method to sleep the calling thread.
static Long_t SelfId()
Static method returning the id for the current thread.