<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ### boost實現線程池 ***** #### 一個io_service 多個線程 ``` using namespace std; using namespace boost; typedef std::shared_ptr<std::thread> thread_ptr; typedef std::vector<thread_ptr> vecThread; class ThreadPool { public: ThreadPool(int num) : threadNum_(num), stopped_(false), work_(io_) { for(int i=i; i<threadNum_; ++i) { threads_.push_back(std::make_shared<std::thread>([&](){io_.run();})); } } ~ThreadPool() { stop(); } template<typename F, typename...Args> void post(F &&f, Args&&...args) { io_.post(std::bind(std::forward<F>(f), std::forward<Args>(args)...)); } void stop() { if(!stopped_) { io_.stop(); for(auto t : threads_) t->join(); stopped_ = true; } } private: bool stopped_; vecThread threads_; int threadNum_; asio::io_service io_; asio::io_service::work work_; }; ``` #### 多個io_serviced多個線程 ``` class AsioIOServicePool { public: using IOService = boost::asio::io_service; using Work = boost::asio::io_service::work; using WorkPtr = std::unique_ptr<Work>; AsioIOServicePool(std::size_t size = std::thread::hardware_concurrency()) : ioServices_(size), works_(size), nextIOService_(0) { for (std::size_t i = 0; i < size; ++i) { works_[i] = std::unique_ptr<Work>(new Work(ioServices_[i])); } for (std::size_t i = 0; i < ioServices_.size(); ++i) { threads_.emplace_back([this, i] () { ioServices_[i].run(); }); } } AsioIOServicePool(const AsioIOServicePool &) = delete; AsioIOServicePool &operator=(const AsioIOServicePool &) = delete; // 使用 round-robin 的方式返回一個 io_service boost::asio::io_service &getIOService() { auto &service = ioServices_[nextIOService_++]; if (nextIOService_ == ioServices_.size()) { nextIOService_ = 0; } return service; } void stop() { for (auto &work: works_) { work.reset(); } for (auto &t: threads_) { t.join(); } } private: std::vector<IOService> ioServices_; std::vector<WorkPtr> works_; std::vector<std::thread> threads_; std::size_t nextIOService_; }; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看