diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 84c0d2af2..3efd7be43 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -294,9 +294,8 @@ multiSlsDetector::~multiSlsDetector() { int multiSlsDetector::createThreadPool(){ - if(threadpool){ - threadpool->destroy_threadpool(); - } + if(threadpool) + destroyThreadPool(); int numthreads = thisMultiDetector->numberOfDetectors; if(numthreads < 1){ numthreads = 1; //create threadpool anyway, threads initialized only when >1 detector added @@ -322,7 +321,6 @@ int multiSlsDetector::createThreadPool(){ void multiSlsDetector::destroyThreadPool(){ if(threadpool){ - threadpool->destroy_threadpool(); delete threadpool; threadpool=0; #ifdef VERBOSE diff --git a/slsDetectorSoftware/threadFiles/Mutex.cpp b/slsDetectorSoftware/threadFiles/Mutex.cpp index 3f7cdca25..4aefec723 100644 --- a/slsDetectorSoftware/threadFiles/Mutex.cpp +++ b/slsDetectorSoftware/threadFiles/Mutex.cpp @@ -7,7 +7,7 @@ Mutex::Mutex() { Mutex::~Mutex() { while(is_locked); - unlock(); // Unlock Mutex after shared resource is safe + //unlock(); // Unlock Mutex after shared resource is safe pthread_mutex_destroy(&m_lock); } diff --git a/slsDetectorSoftware/threadFiles/ThreadPool.cpp b/slsDetectorSoftware/threadFiles/ThreadPool.cpp index 9a1dfddce..63ca4824a 100644 --- a/slsDetectorSoftware/threadFiles/ThreadPool.cpp +++ b/slsDetectorSoftware/threadFiles/ThreadPool.cpp @@ -1,5 +1,5 @@ #include "ThreadPool.h" - +#include ThreadPool::ThreadPool(int pool_size) : m_pool_size(pool_size){ #ifdef VERBOSE @@ -62,24 +62,29 @@ int ThreadPool::destroy_threadpool(){ //to other threads until its modified in a lock! m_task_mutex.lock(); m_pool_state = STOPPED; - m_task_mutex.unlock(); /*cout << "Broadcasting STOP signal to all threads..." << endl;*/ m_task_cond_var.broadcast(); // notify all threads we are shttung down + m_task_mutex.unlock(); // int ret = -1; for (int i = 0; i < m_pool_size; i++) { - void* result; sem_post(&semStart); sem_post(&semDone); - //ret = + + void* result; pthread_join(m_threads[i], &result); /*cout << "pthread_join() returned " << ret << ": " << strerror(errno) << endl;*/ + m_task_mutex.lock(); m_task_cond_var.broadcast(); // try waking up a bunch of threads that are still waiting + m_task_mutex.unlock(); } + + sem_destroy(&semStart); sem_destroy(&semDone); number_of_ongoing_tasks = 0; number_of_total_tasks = 0; + /* cout << m_pool_size << " threads exited from the thread pool" << endl;*/ return 0; }