Boost::asio::io_service::work class

Source: Internet
Author: User

Source: http://blog.csdn.net/pud_zha/article/details/37561011

Work is a small helper class that supports only constructors and destructors. (There is also a get_io_service returned by the associated Io_service) when constructing a work, outstanding_work_+1, so that io.run when the completion of all asynchronous messages after the judgment Outstanding_work_ will not be 0, Therefore, it will continue to call GetQueuedCompletionStatus and block on this function.
And the destructor will be 1, and determine if it is 0, if so, then post exit message to GetQueuedCompletionStatus let it exit.


So if work is refactored, io.run exits normally after all messages have been processed. Work if you do not refactor, the Io.run will run without exiting. If the user calls Io.stop directly, it causes Io.run to exit immediately.


It is particularly important to note that work provides a copy constructor so that it can be used directly anywhere. For a io_service, how many work instances are associated, then Outstanding_work_ + 1 How many times, only work connected to the same io_service is all


After destruction, io.run exits normally after all message processing has ended.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.