Boost.Asio thread safety

左心房为你撑大大i 提交于 2019-12-01 08:24:03
Sam Miller

Is it safe to call async_write & async_read from different threads

Yes, but with a caveat. You can safely do this for distinct socket objects

Thread Safety

Distinct objects: Safe.

Shared objects: Unsafe.

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

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..

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!