| 440 | } |
| 441 | |
| 442 | void io_context_executor_execute_test() |
| 443 | { |
| 444 | io_context ioc; |
| 445 | int count = 0; |
| 446 | |
| 447 | ioc.get_executor().execute(bindns::bind(increment, &count)); |
| 448 | |
| 449 | // No handlers can be called until run() is called. |
| 450 | BOOST_ASIO_CHECK(!ioc.stopped()); |
| 451 | BOOST_ASIO_CHECK(count == 0); |
| 452 | |
| 453 | ioc.run(); |
| 454 | |
| 455 | // The run() call will not return until all work has finished. |
| 456 | BOOST_ASIO_CHECK(ioc.stopped()); |
| 457 | BOOST_ASIO_CHECK(count == 1); |
| 458 | |
| 459 | count = 0; |
| 460 | ioc.restart(); |
| 461 | boost::asio::require(ioc.get_executor(), |
| 462 | boost::asio::execution::blocking.possibly |
| 463 | ).execute(bindns::bind(increment, &count)); |
| 464 | |
| 465 | // No handlers can be called until run() is called. |
| 466 | BOOST_ASIO_CHECK(!ioc.stopped()); |
| 467 | BOOST_ASIO_CHECK(count == 0); |
| 468 | |
| 469 | ioc.run(); |
| 470 | |
| 471 | // The run() call will not return until all work has finished. |
| 472 | BOOST_ASIO_CHECK(ioc.stopped()); |
| 473 | BOOST_ASIO_CHECK(count == 1); |
| 474 | |
| 475 | count = 0; |
| 476 | ioc.restart(); |
| 477 | boost::asio::require(ioc.get_executor(), |
| 478 | boost::asio::execution::blocking.never |
| 479 | ).execute(bindns::bind(increment, &count)); |
| 480 | |
| 481 | // No handlers can be called until run() is called. |
| 482 | BOOST_ASIO_CHECK(!ioc.stopped()); |
| 483 | BOOST_ASIO_CHECK(count == 0); |
| 484 | |
| 485 | ioc.run(); |
| 486 | |
| 487 | // The run() call will not return until all work has finished. |
| 488 | BOOST_ASIO_CHECK(ioc.stopped()); |
| 489 | BOOST_ASIO_CHECK(count == 1); |
| 490 | |
| 491 | count = 0; |
| 492 | ioc.restart(); |
| 493 | BOOST_ASIO_CHECK(!ioc.stopped()); |
| 494 | |
| 495 | boost::asio::require(ioc.get_executor(), |
| 496 | boost::asio::execution::blocking.never, |
| 497 | boost::asio::execution::outstanding_work.tracked |
| 498 | ).execute(bindns::bind(increment, &count)); |
| 499 | |