Exemplo n.º 1
0
void start_threads(thread_vector& threads,
                   action_counts& actions,
                   void* args = 0) {
    action_counts::iterator b = actions.begin(), e = actions.end();
    for(action_counts::iterator i = b; i != e; ++i) {
        for(unsigned count = 0; count < i->first; ++count) {
            pthread_t t;
            pthread_create(&t, 0, i->second, args);
            threads.push_back(t);
        }
    }
}
Exemplo n.º 2
0
 thread_pool(unsigned int count) {
     mine::ths_in_use = true;
     /* Adding a try catch is more powerful, but this place just for use. */
     cout << " Initialize the thread pool :" << endl;
     for (unsigned int i = 0; i < count; i++) {
         /* use boost::move in the future to get more compatible. */
         /* And now, it is an ADL problem, conflicts.*/
         thread_t tt;
         tt.t = new boost::thread(boost::bind(&thread_pool::worker_thread, this));
         threads.push_back(tt);
         cout << "   Thread " << i << " in the thread pool"
              << " is going to run!" << endl;
     }
 }
Exemplo n.º 3
0
 /* Join all the threads. */
 void join_all() {
     for (unsigned int i = 0; i < threads.size(); i++) {
         threads[i].t->join();
     }
 }