[Boost] ASIO explanation of boost library 2 -- io_service: exit when the run function has no task

Source: Internet
Author: User

The io_service: Work class can enable the io_service: Run function to not return the result when no task exists until the work object is destroyed.

Void test_asio_nowork () {boost: ASIO: io_service Ios; print_debug ("iOS before"); IOs. run (); print_debug ("iOS end");} void test_asio_work () {boost: ASIO: io_service Ios; // Add a work object boost: ASIO :: io_service: Work work (IOS); print_debug ("iOS before"); // IOS. run () does not return IOS immediately. run (); print_debug ("iOS end ");}

Test_asio_nowork () execution result:

22:43:19 334 [4868] Debug-Ios before2013-01-05 22:43:19 341 [4868] Debug-Ios end

Execution result of test_asio_work:

22:43:48 514 [7852] Debug-Ios before

When there is no task, it will also be blocked.

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.