34 const size_t g_sleeptime = 2;
35 const size_t g_multTasks = 10;
38 enum EProc {start, clean};
42 bool runTask(EProc ) {
47 unsigned long threadID()
const {
54 ostream &
operator<< (ostream &_stream,
const TTestTask &_task)
56 _stream << _task.threadID();
61 void stressThreadPool(
size_t _numThreads = 5,
bool _needDbg =
false)
63 size_t numTasks(_numThreads * g_multTasks);
65 vector <TTestTask> tasksList(numTasks);
68 for (
size_t j = 0; j < 4; ++j )
70 cout <<
"+++++++++ Starting iteration #" << j <<
" ++++++++++++"<< endl;
71 for (
size_t i = 0; i < numTasks; ++i) {
72 threadPool.PushTask(tasksList[i], start);
75 cout <<
"\n ****** Drain the tasks queue ******" << endl;
78 cout <<
"\n Stopping..." << endl;
79 threadPool.Stop(
true);
85 typedef map<unsigned long, size_t> counter_t;
88 vector <TTestTask>::const_iterator iter = tasksList.begin();
89 vector <TTestTask>::const_iterator iter_end = tasksList.end();
90 for (; iter != iter_end; ++iter) {
91 counter_t::iterator found = counter.find(iter->threadID());
92 if (found == counter.end())
93 counter.insert(counter_t::value_type(iter->threadID(), 1));
95 found->second = found->second + 1;
100 cout <<
"\n************* RESULT ****************" << endl;
102 counter_t::const_iterator iter = counter.begin();
103 counter_t::const_iterator iter_end = counter.end();
105 for (; iter != iter_end; ++iter) {
106 cout <<
"Thread " << iter->first <<
" was used " << iter->second <<
" times\n";
109 if (iter->second != g_multTasks)
113 cout <<
"ThreadPool: the simple test status: " << (testOK ?
"OK" :
"Failed") << endl;
RooArgList L(const RooAbsArg &v1)
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
static Long_t SelfId()
Static method returning the id for the current thread.
static Int_t Sleep(ULong_t secs, ULong_t nanos=0)
Static method to sleep the calling thread.