MCPcopy Create free account
hub / github.com/boostorg/asio / strand_execute_test

Function strand_execute_test

test/strand.cpp:272–431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

270}
271
272void 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.

Callers

nothing calls this directly

Calls 9

make_strandFunction · 0.85
restartMethod · 0.80
bindFunction · 0.50
requireFunction · 0.50
preferFunction · 0.50
allocatorClass · 0.50
executeMethod · 0.45
stoppedMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected