concurrency_hint of boost::asio::io_service 是什么意思?
What does concurrency_hint of boost::asio::io_service means?
来自 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.
'A suggestion to the implementation'是什么意思?
如果我用'2'构造对象,它可以只启动1个线程吗?
如果我有一个具有 4 个内核的 CPU 并且我用“4”或“5”构造对象会发生什么?
并发提示允许底层实现根据应该 运行 io_service
的并发线程数量做出选择。例如:
对于I/O个完成端口,它设置完成端口的最大并发级别。并发提示作为 NumberOfConcurrentThreads
参数提供给 CreateIoCompletionPort()
。有关详细信息,请参阅 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.
来自 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.
'A suggestion to the implementation'是什么意思?
如果我用'2'构造对象,它可以只启动1个线程吗?
如果我有一个具有 4 个内核的 CPU 并且我用“4”或“5”构造对象会发生什么?
并发提示允许底层实现根据应该 运行 io_service
的并发线程数量做出选择。例如:
对于I/O个完成端口,它设置完成端口的最大并发级别。并发提示作为
NumberOfConcurrentThreads
参数提供给CreateIoCompletionPort()
。有关详细信息,请参阅 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.