| 270 | } |
| 271 | |
| 272 | void strand_execute_test() |
| 273 | { |
| 274 | io_context ioc; |
| 275 | strand<io_context::executor_type> s1 = make_strand(ioc); |
| 276 | int count = 0; |
| 277 | |
| 278 | s1.execute(bindns::bind(increment, &count)); |
| 279 | |
| 280 | // No handlers can be called until run() is called. |
| 281 | BOOST_ASIO_CHECK(!ioc.stopped()); |
| 282 | BOOST_ASIO_CHECK(count == 0); |
| 283 | |
| 284 | ioc.run(); |
| 285 | |
| 286 | // The run() call will not return until all work has finished. |
| 287 | BOOST_ASIO_CHECK(ioc.stopped()); |
| 288 | BOOST_ASIO_CHECK(count == 1); |
| 289 | |
| 290 | count = 0; |
| 291 | ioc.restart(); |
| 292 | boost::asio::require(s1, boost::asio::execution::blocking.possibly).execute( |
| 293 | bindns::bind(increment, &count)); |
| 294 | |
| 295 | // No handlers can be called until run() is called. |
| 296 | BOOST_ASIO_CHECK(!ioc.stopped()); |
| 297 | BOOST_ASIO_CHECK(count == 0); |
| 298 | |
| 299 | ioc.run(); |
| 300 | |
| 301 | // The run() call will not return until all work has finished. |
| 302 | BOOST_ASIO_CHECK(ioc.stopped()); |
| 303 | BOOST_ASIO_CHECK(count == 1); |
| 304 | |
| 305 | count = 0; |
| 306 | ioc.restart(); |
| 307 | boost::asio::require(s1, boost::asio::execution::blocking.never).execute( |
| 308 | bindns::bind(increment, &count)); |
| 309 | |
| 310 | // No handlers can be called until run() is called. |
| 311 | BOOST_ASIO_CHECK(!ioc.stopped()); |
| 312 | BOOST_ASIO_CHECK(count == 0); |
| 313 | |
| 314 | ioc.run(); |
| 315 | |
| 316 | // The run() call will not return until all work has finished. |
| 317 | BOOST_ASIO_CHECK(ioc.stopped()); |
| 318 | BOOST_ASIO_CHECK(count == 1); |
| 319 | |
| 320 | count = 0; |
| 321 | ioc.restart(); |
| 322 | BOOST_ASIO_CHECK(!ioc.stopped()); |
| 323 | |
| 324 | boost::asio::require(s1, |
| 325 | boost::asio::execution::blocking.never, |
| 326 | boost::asio::execution::outstanding_work.tracked |
| 327 | ).execute(bindns::bind(increment, &count)); |
| 328 | |
| 329 | // No handlers can be called until run() is called. |