设置c ++ std :: thread的亲和性

时间:2014-06-04 17:41:03

标签: c++ windows multithreading c++11 std

我想在UDP数据报到达时在Windows中进行精确的时间测量。从Microsoft读取文档我决定使用QueryPerformanceCounter。在同一文档中,它建议您设置计时线程的亲和性和性能。我正在使用Boost和c ++ 11来实现我的异步UDP服务器:

void receiveEvent()
{
  listening_socket.async_receive_from(
    boost::asio::buffer(event_buffer, max_length), signaling_endpoint,
    [this](boost::system::error_code ec, std::size_t bytes_recvd)
    {
      if (!ec && bytes_recvd > 0)
      {
        LARGE_INTEGER prectime;
        ::QueryPerformanceCounter(&prectime);
        std::cout << prectime.QuadPart << std::endl;
      } else if (ec == boost::asio::error::operation_aborted) {
        std::cout << "socket canceled" << std::endl;
        return;
      }
      receiveEvent();
    });
}

listening_socket(io, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port));
receiveEvent();
async_thread = std::thread(boost::bind(&boost::asio::io_service::run, &io));
// TODO set thread affinity using SetProcessAffinityMask
// TODO set thread priority using SetPriorityClass

如何将std::thread async_threadSetProcessAffinityMaskSetPriorityClass一起使用?

0 个答案:

没有答案