开发者

Waiting for completing of asynchronous operations

开发者 https://www.devze.com 2023-02-18 03:53 出处:网络
HI all! There is an io_service object, methods run() works in a thread pool. There are set of classes, which make async write using ip::tcp::socket.

HI all!

There is an io_service object, methods run() works in a thread pool. There are set of classes, which make async write using ip::tcp::socket. I need to block destructor of this kind of class, until his tasks live in the io_service's queue. In example, 开发者_如何学运维to add method join(). But what the reason to block the destructor?


I'm not sure if I understand your question correctly, but it sounds like you want to make sure that classes that are waiting for outstanding async operations are not destroyed before the operation completes?

The enable_shared_from_this idiom can be used for this purpose and is demonstrated e.g. in http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/tutorial/tutdaytime7/src.html. If you look at tcp_connection::start you see how the class passes a shared_ptr to itself to bind as the handler for the async operation.


Solved like this: http://liveworkspace.org/code/7665b7170b3311085fff2e84710d4350

Thanks for all.

0

精彩评论

暂无评论...
验证码 换一张
取 消