From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- .../libs/fiber/test/test_barrier_dispatch.cpp | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/boost/libs/fiber/test/test_barrier_dispatch.cpp (limited to 'src/boost/libs/fiber/test/test_barrier_dispatch.cpp') diff --git a/src/boost/libs/fiber/test/test_barrier_dispatch.cpp b/src/boost/libs/fiber/test/test_barrier_dispatch.cpp new file mode 100644 index 00000000..8f1716d5 --- /dev/null +++ b/src/boost/libs/fiber/test/test_barrier_dispatch.cpp @@ -0,0 +1,71 @@ + +// Copyright Oliver Kowalke 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// This test is based on the tests of Boost.Thread + +#include +#include + +#include + +#include + +int value1 = 0; +int value2 = 0; + +void fn1( boost::fibers::barrier & b) { + ++value1; + boost::this_fiber::yield(); + + b.wait(); + + ++value1; + boost::this_fiber::yield(); + ++value1; + boost::this_fiber::yield(); + ++value1; + boost::this_fiber::yield(); + ++value1; +} + +void fn2( boost::fibers::barrier & b) { + ++value2; + boost::this_fiber::yield(); + ++value2; + boost::this_fiber::yield(); + ++value2; + boost::this_fiber::yield(); + + b.wait(); + + ++value2; + boost::this_fiber::yield(); + ++value2; +} + +void test_barrier() { + value1 = 0; + value2 = 0; + + boost::fibers::barrier b( 2); + boost::fibers::fiber f1( boost::fibers::launch::dispatch, fn1, std::ref( b) ); + boost::fibers::fiber f2( boost::fibers::launch::dispatch, fn2, std::ref( b) ); + + f1.join(); + f2.join(); + + BOOST_CHECK_EQUAL( 5, value1); + BOOST_CHECK_EQUAL( 5, value2); +} + +boost::unit_test::test_suite * init_unit_test_suite( int, char* []) { + boost::unit_test::test_suite * test = + BOOST_TEST_SUITE("Boost.Fiber: barrier test suite"); + + test->add( BOOST_TEST_CASE( & test_barrier) ); + + return test; +} -- cgit v1.2.3