changes to test

This commit is contained in:
Dhanya Maliakal
2016-08-15 15:14:15 +02:00
parent 597f5e5d2a
commit fb8f49985b
2 changed files with 22 additions and 21 deletions

View File

@ -1608,7 +1608,7 @@ int* multiSlsDetector::startAndReadAll(){
int multiSlsDetector::startAndReadAllNoWait(){ int multiSlsDetector::startAndReadAllNoWait(){
/*
int i=0; int i=0;
int ret=OK, ret1=OK; int ret=OK, ret1=OK;
@ -1636,7 +1636,7 @@ int multiSlsDetector::startAndReadAllNoWait(){
} }
return ret1; return ret1;
/* */
// hanging randomly around 4000-5000 frames at 1sec exptime (threads dont return) // hanging randomly around 4000-5000 frames at 1sec exptime (threads dont return)
int i=0; int i=0;
int ret=OK; int ret=OK;
@ -1653,9 +1653,10 @@ int multiSlsDetector::startAndReadAllNoWait(){
Task* task = new Task(new func0_t<int,slsDetector,int>(&slsDetector::startAndReadAllNoWait, Task* task = new Task(new func0_t<int,slsDetector,int>(&slsDetector::startAndReadAllNoWait,
detectors[idet],iret[idet])); detectors[idet],iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
cprintf(GREEN,"task addeD\n");
} }
} }cout<<"waiting for tasks to copmlete"<<endl;
threadpool->wait_for_tasks_to_complete(); threadpool->wait_for_tasks_to_complete();cout<<"returned!"<<endl;
for(int idet=posmin; idet<posmax; idet++){ for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){ if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
if(iret[idet] != NULL){ if(iret[idet] != NULL){
@ -1672,7 +1673,7 @@ int multiSlsDetector::startAndReadAllNoWait(){
//master //master
int ret1=OK; int ret1=OK;
i=thisMultiDetector->masterPosition; i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) { if (thisMultiDetector->masterPosition>=0) {cout<<"should never be here"<<endl;
if (detectors[i]) { if (detectors[i]) {
ret1=detectors[i]->startAndReadAllNoWait(); ret1=detectors[i]->startAndReadAllNoWait();
if(detectors[i]->getErrorMask()) if(detectors[i]->getErrorMask())
@ -1683,7 +1684,7 @@ int multiSlsDetector::startAndReadAllNoWait(){
} }
return ret; return ret;
*/
} }

View File

@ -121,29 +121,29 @@ void* ThreadPool::execute_thread()
/*cout << "Unlocking: " << pthread_self() << endl;*/ /*cout << "Unlocking: " << pthread_self() << endl;*/
m_task_mutex.unlock(); m_task_mutex.unlock();
//cout << "Executing thread " << pthread_self() << endl; cout << ithread <<" Executing thread " << pthread_self() << endl;
// execute the task // execute the task
(*task)(); // could also do task->run(arg); (*task)(); // could also do task->run(arg);
//cout << "Done executing thread " << pthread_self() << endl; cout << ithread <<" Done executing thread " << pthread_self() << endl;
m_all_tasks_mutex.lock(); m_all_tasks_mutex.lock();
number_of_ongoing_tasks--; // cout<<"number_of_ongoing_tasks:"<<number_of_ongoing_tasks<<endl; number_of_ongoing_tasks--; cout<<ithread <<" number_of_ongoing_tasks:"<<number_of_ongoing_tasks<<endl;
m_all_tasks_mutex.unlock(); m_all_tasks_mutex.unlock();
//if all required tasks done //if all required tasks done
if(!ithread && m_tasks_loaded && (m_tasks.empty())){ if(!ithread && m_tasks_loaded && (m_tasks.empty())){cout<<ithread <<" waiting for all tasks to be done"<<endl;
while(number_of_ongoing_tasks) while(number_of_ongoing_tasks)
usleep(5000); usleep(5000);
cout<<ithread <<" all tasks done. gonna lock"<<endl;
m_all_tasks_mutex.lock(); m_all_tasks_mutex.lock(); cout<<ithread <<" all tasks done"<<endl;
m_tasks_loaded = false; //cout<<"all tasks done"<<endl; m_tasks_loaded = false; cout<<ithread <<" task loaded set to false"<<endl;
m_all_tasks_cond_var.signal(); // wake up thread that is waiting for all tasks to be complete m_all_tasks_cond_var.signal(); cout<<ithread <<" wake up signal sent"<<endl;// wake up thread that is waiting for all tasks to be complete
m_all_tasks_mutex.unlock(); m_all_tasks_mutex.unlock();cout<<ithread <<" unlocked"<<endl;
} }
delete task; delete task;cout<<ithread <<" task deleted"<<endl;
} }
return NULL; return NULL;
} }
@ -167,12 +167,12 @@ void ThreadPool::wait_for_tasks_to_complete(){
if(m_pool_size == 1) if(m_pool_size == 1)
return; return;
m_all_tasks_mutex.lock(); m_all_tasks_mutex.lock();cout<<"waiting for tasks: locked. gonna wait" <<endl;
m_tasks_loaded = true; m_tasks_loaded = true;
while ((m_pool_state != STOPPED) && m_tasks_loaded) { while ((m_pool_state != STOPPED) && m_tasks_loaded) {cout<<"waiting for tasks: checking should be locked most likely, m_tasks_loaded:"<<m_tasks_loaded <<endl;
m_all_tasks_cond_var.wait(m_all_tasks_mutex.get_mutex_ptr()); m_all_tasks_cond_var.wait(m_all_tasks_mutex.get_mutex_ptr());cout<<"waiting for tasks: out of the wait loop, m_tasks_loaded:"<< m_tasks_loaded<<endl;
} }cout<<"waiting for tasks:totall out, must be locked again" <<endl;
m_all_tasks_mutex.unlock(); m_all_tasks_mutex.unlock();cout<<"waiting for tasks: unlocked and done" <<endl;
} }