Boost::asio 并发性(?)
我正在编译 boost::asio 示例: http://www.boost .org/doc/libs/1_46_1/doc/html/boost_asio/examples.html#boost_asio.examples.http_server_3
应该是一个多线程服务器实现。
现在,在 async_read 处理程序中,我打印一条消息并休眠 30 秒。我在两个浏览器中打开 localhost,看到handle_read被调用一次,然后30秒没有任何反应,最后handle_read被第二次调用。
使用 5 个线程调用 io_Service.run。
为什么处理程序没有同时调用?例如,为什么它要等待第一个handle_read完成后再调用第二个?
I am compiling the boost::asio example:
http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/examples.html#boost_asio.examples.http_server_3
It is supposed to be a multi-threaded server implementation.
Now, in the async_read handler I print a message and sleep for 30 seconds. I open localhost in two browsers and see that handle_read is called once, then 30 seconds nothing happens and finally handle_read is called for the second time.
The io_Service.run is called with 5 threads.
Why aren't the handlers called concurrently? e.g. why does it wait for the first handle_read to finish before calling the second?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它有助于发布代码。当我对asio示例使用此修改时:
它按预期工作,即
How do you“sleep for 30秒”?也许您使用的 sleep 函数会暂停进程中的所有线程?
It helps to post code. When I use this modification to the asio example:
it works as expected, that is
How do you "sleep for 30 seconds"? Perhaps the sleep function you've used pauses all threads in the process?