Threadpool(unsigned thrd_cnt, const std::function<void(unsigned inst)>& f) : _f(f) {
            unsigned cores = boost::thread::hardware_concurrency();

            Logger::pLOG->info("Found {} cores for DOR", cores);

            if (thrd_cnt == 0 || thrd_cnt > cores)
                thrd_cnt = cores;

            for (unsigned i = 0; i < thrd_cnt; ++i) {
                boost::thread* t = _tg.create_thread([this, i](){ Threadpool::_f(i); });

                //The thread name is a meaningful C language string, whose length is
                //restricted to 16 characters, including the terminating null byte ('\0')
                std::string s = "DOR-THRD-" + std::to_string(i);
                Logger::pLOG->info("Created {}", s);

#ifdef __linux__
                if (pthread_setname_np(t->native_handle(), s.data()))
                    Logger::pLOG->warn("Could not set name for {}", s);

                struct sched_param param {};
                param.sched_priority = RT_PRIO;

                if (pthread_setschedparam(t->native_handle(), SCHED_FIFO, &param))
                    Logger::pLOG->warn("Could not set realtime parameter for {}", s);
#endif
            }

            Logger::pLOG->info("DOR has {} thread/s running", _tg.size());
        }
    void start()
    {
        if (m_threads.size() > 0)
        {   return; }

        for(ios_type& ios : m_io_services)
        {
            m_threads.create_thread(
                boost::bind(&ios_type::run, 
                    boost::ref(ios)));
        }
    }
Beispiel #3
0
void waitTermination( boost::thread_group& threads, std::initializer_list< int > signals = { SIGINT, SIGTERM, SIGQUIT } )
{
     sigset_t sset;

     sigemptyset( &sset );

     for( const auto each: signals )
     {
          sigaddset( &sset, each );
     }

     sigprocmask( SIG_BLOCK, &sset, nullptr );

     std::cout << "threads running: " << threads.size() << "; main thread waiting for termination signals...\n";

     int sig = 0;
     sigwait( &sset, &sig );

     std::cout << "termination signal " << sig << " has been caught\n" << "interrupting threads...\n";

     threads.interrupt_all();
}
Beispiel #4
0
	size_type size() const
	{
      return my_group.size();
	}