In example 3 of the HTTP server (boost 2.44), the IO service is created without a thread count hint. Under Windows, one normally passes the thread count to CreateIoCompletionPort(). boost:asio has an IO Service ctor that takes the thread count, but that ctor is not used in this example. And the thread count is known.
在HTTP服务器的示例3(boost 2.44)中,创建的IO服务没有线程计数提示。在Windows下,通常会将线程计数传递给CreateIoCompletionPort()。 boost:asio有一个IO服务ctor,它接受线程计数,但在这个例子中没有使用ctor。线程数已知。
My question is: is there a reason to create the IO Service without the thread count? Does boost:asio assume one would never create more threads than one per core? Note if the thread count passed to CreateIoCompletionPort() is zero, the system will allow one thread per core concurrently running threads.
我的问题是:有没有理由在没有线程计数的情况下创建IO服务? boost:asio假设一个人永远不会创建比每个核心更多的线程吗?请注意,如果传递给CreateIoCompletionPort()的线程数为零,则系统将允许每个核心一个线程同时运行线程。
2 个解决方案
#1
0
When you call the parameter-less constructor on io_service
, the call to CreateIoCompletionPort
winds up using a thread count of 0xffffffff in the code here:
当您在io_service上调用无参数构造函数时,对CreateIoCompletionPort的调用将在此处的代码中使用0xffffffff的线程计数结束:
void win_iocp_io_service::init(size_t concurrency_hint)
{
iocp_.handle = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0,
static_cast<DWORD>((std::min<size_t>)(concurrency_hint, DWORD(~0))));
if (!iocp_.handle)
{
DWORD last_error = ::GetLastError();
boost::system::error_code ec(last_error,
boost::asio::error::get_system_category());
boost::asio::detail::throw_error(ec, "iocp");
}
}
Not sure how Windows interprets this but the call works OK, so I assume this is the same as using 0. I guess the assumption is that the OS knows best?
不确定Windows如何解释这个,但调用工作正常,所以我认为这与使用0相同。我猜这个假设是操作系统最了解?
#2
0
When concurrency_hint
is not specified to boost:asio::io_service()
constructor. Default is infinite or unbounded, which is never the best practice. But the designer probably felt this Windows based concurrency_hint was unnecessary, so made the default consistent with all platforms (no limit). This is likely to be consistent with how other OS interpret this value.
当concurrency_hint未指定为boost:asio :: io_service()构造函数时。默认是无限的或无限的,这绝不是最好的做法。但设计人员可能认为这种基于Windows的concurrency_hint是不必要的,因此默认情况下与所有平台一致(无限制)。这很可能与其他操作系统解释此值的方式一致。
Since Windows itself creates no threads out of this whole fiasco, it shouldn't even care. concurrency_hint
should be renamed max_allowed_concurrency_on_Windows
由于Windows本身没有创造出整个惨败的线程,它甚至不应该关心。 concurrency_hint应重命名为max_allowed_concurrency_on_Windows
#1
0
When you call the parameter-less constructor on io_service
, the call to CreateIoCompletionPort
winds up using a thread count of 0xffffffff in the code here:
当您在io_service上调用无参数构造函数时,对CreateIoCompletionPort的调用将在此处的代码中使用0xffffffff的线程计数结束:
void win_iocp_io_service::init(size_t concurrency_hint)
{
iocp_.handle = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0,
static_cast<DWORD>((std::min<size_t>)(concurrency_hint, DWORD(~0))));
if (!iocp_.handle)
{
DWORD last_error = ::GetLastError();
boost::system::error_code ec(last_error,
boost::asio::error::get_system_category());
boost::asio::detail::throw_error(ec, "iocp");
}
}
Not sure how Windows interprets this but the call works OK, so I assume this is the same as using 0. I guess the assumption is that the OS knows best?
不确定Windows如何解释这个,但调用工作正常,所以我认为这与使用0相同。我猜这个假设是操作系统最了解?
#2
0
When concurrency_hint
is not specified to boost:asio::io_service()
constructor. Default is infinite or unbounded, which is never the best practice. But the designer probably felt this Windows based concurrency_hint was unnecessary, so made the default consistent with all platforms (no limit). This is likely to be consistent with how other OS interpret this value.
当concurrency_hint未指定为boost:asio :: io_service()构造函数时。默认是无限的或无限的,这绝不是最好的做法。但设计人员可能认为这种基于Windows的concurrency_hint是不必要的,因此默认情况下与所有平台一致(无限制)。这很可能与其他操作系统解释此值的方式一致。
Since Windows itself creates no threads out of this whole fiasco, it shouldn't even care. concurrency_hint
should be renamed max_allowed_concurrency_on_Windows
由于Windows本身没有创造出整个惨败的线程,它甚至不应该关心。 concurrency_hint应重命名为max_allowed_concurrency_on_Windows