Example #1
0
  void thread_pool::resize(size_t nthreads) {
    // if the current pool size does not equal the requested number of
    // threads shut the pool down and startup with correct number of
    // threads.  \todo: If the pool size is too small just add
    // additional threads rather than destroying the pool
    if(nthreads != pool_size) {
      pool_size = nthreads;

      // stop the queue from blocking
      spawn_queue.stop_blocking();
    
      // join the threads in the thread group
      while(true) {
        try {
          threads.join(); break;
        } catch (const char* error_str) {
          // this should not be possible!
          logstream(LOG_FATAL) 
            << "Unexpected exception caught in thread pool destructor: " 
            << error_str << std::endl;
        }
      }
      spawn_queue.start_blocking();
      spawn_thread_group();
    }
  } // end of set_nthreads
Example #2
0
 thread_pool::thread_pool(size_t nthreads, bool affinity) {
   waiting_on_join = false;
   tasks_inserted = 0;
   tasks_completed = 0;
   cpu_affinity = affinity;
   pool_size = nthreads;
   spawn_thread_group();
 } // end of thread_pool
Example #3
0
 void thread_pool::set_cpu_affinity(bool affinity) {
   if (affinity != cpu_affinity) {
     cpu_affinity = affinity;
     // stop the queue from blocking
     spawn_queue.stop_blocking();
   
     // join the threads in the thread group
     while(1) {
       try {
         threads.join(); break;
       } catch (const char* c) {
         // this should not be possible!
         logstream(LOG_FATAL) 
           << "Unexpected exception caught in thread pool destructor: " 
           << c << std::endl;
         // ASSERT_TRUE(false); // unnecessary
       }
     }
     spawn_queue.start_blocking();
     spawn_thread_group();
   }
 } // end of set_cpu_affinity
Example #4
0
thread_pool::thread_pool(size_t nthreads, bool affinity) {
  cpu_affinity = affinity;
  pool_size = nthreads;
  spawn_thread_group();
} // end of thread_pool