c++ - boost::asio::io_service 的 concurrency_hint 是什么意思?

标签 c++ multithreading boost boost-asio

来自boost doc :

io_service( std::size_t concurrency_hint);
Construct with a hint about the required level of concurrency.

Parameters

concurrency_hint A suggestion to the implementation on how many threads it should allow to run simultaneously.

“实现建议”是什么意思?

如果我用“2”构造对象,它只能启动1个线程吗?
如果我有一个 4 核的 CPU,并且我用“4”或“5”构造对象,会发生什么?

最佳答案

并发提示允许底层实现根据应运行 io_service 的并发线程数量做出选择。例如:

  • 对于 I/O 完成端口,它设置完成端口的最大并发级别。并发提示作为 CreateIoCompletionPort()NumberOfConcurrentThreads 参数提供。请参阅I/O Completion Ports有关更多详细信息的文档:

    This value limits the number of runnable threads associated with the completion port. When the total number of runnable threads associated with the completion port reaches the concurrency value, the system blocks the execution of any subsequent threads associated with that completion port until the number of runnable threads drops below the concurrency value.

  • 当设置为 1 时,会优化实现以避免不必要的锁定。 Revision History备注:

    Using thread-local operation queues in single-threaded use cases (i.e. when concurrency_hint is 1) to eliminate a lock/unlock pair.

关于c++ - boost::asio::io_service 的 concurrency_hint 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40829143/

相关文章:

c++ - OpenGL 多位 Alpha 纹理

java - 检测写入标准错误流

java - 线程对方法的请求计数器

c++ - 预处理器宏代码中的语法错误

c++ - 有人可以解释使用库 <stdint.h> 中的 uint32_t 的意义吗?

c++ - 错误 C2593 : 'operator +' is ambiguous

c++ - Boost message_queue : just the constructor lets me configure it, 无其他成员函数可用

c++ - 在 Boost program_options 中解析配置文件的未注册选项?

c++ - Qt metaObject 链接器问题

android - notifyDataSetChanged 不适用于 Thread