#include "Multi.h" #include "Single.h" #include "ThreadPool.h" #include #include #include #include using namespace std; char ans[1000]; int threadflag = 1; Multi::Multi() { numSingles = 1; threadpool = 0; for(int i=0;idestroy_threadpool(); threadpool=0; } if(numSingles > 0) threadpool = new ThreadPool(numSingles); switch(threadpool->initialize_threadpool()){ case -1: cerr << "Failed to initialize thread pool!" << endl; return 0; case 0: cout << "Not initializing threads, only one detector" << endl; break; default: cout << "Initialized Threadpool" << endl; break; } return 1; } int Multi::destroyThreadPool(){ if(threadpool){ threadpool->destroy_threadpool(); threadpool=0; cout<<"Destroyed Threadpool"<* binder = // new func_t(&Single::printNumber,singles[i],inum,iret[i]); Task* task = new Task(new func1_t(&Single::printNumber,singles[i],inum,iret[i])); threadpool->add_task(task); } threadpool->wait_for_tasks_to_complete(); for(int i=0;i1){ string* sret[numSingles]; for(int i=0;i* binder = new func1_t(&Single::printString,singles[i],s,sret[i]); Task* task = new Task(binder); threadpool->add_task(task); } threadpool->wait_for_tasks_to_complete(); for(int i=0;iprintString(s); if(ret=="error") ret = ret1; else if (ret != ret1) ret = "sss"; } } return ret; } char* Multi::printCharArray(char a[]){ string ret="error", ret1="sss"; if(numSingles>1){ string* sret[numSingles]; for(int i=0;i* binder = new func1_t (&Single::printCharArray,singles[i],a,sret[i]); Task* task = new Task(binder); threadpool->add_task(task); } threadpool->wait_for_tasks_to_complete(); for(int i=0;iprintCharArray(a); if(ret=="error") ret = ret1; else if (ret != ret1) ret = "sss"; } } strcpy(ans,ret.c_str()); return ans; }