gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 21:55:31 24 4
gpt4 key购买 nike

来自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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com