Boost.Asio线程安全 [英] Boost.Asio thread safety

查看:99
本文介绍了Boost.Asio线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用async_write&是否安全?当仅从一个线程调用io_service :: run()时,会从不同线程读取async_read吗? 谢谢!

Is it safe to call async_write & async_read from different threads in situation when io_service::run() was called from only one thread? Thank you!

推荐答案

文档对此很保守,说不".

The documentation is conservative on that and says "no".

但是我还是在我的linux程序之一中执行此操作,它似乎工作正常.深入研究boost/asio/detail/epoll_reactor.ipp表明,函数start_op()确实受到互斥锁的保护,因此我的信心得到了提高.

But I'm doing this anyway in one of my linux programs and it seems to work fine. Digging into boost/asio/detail/epoll_reactor.ipp shows that the function start_op() is indeed protected by a mutex, so my confidence is increased.

但是其他平台可能有所不同..

But other platforms may be different..

这篇关于Boost.Asio线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆